I have built an camera and library app where I am choosing image from my library and showing it to an imageView. But the problem that is happening is after choosing the image is not showing in imageView.
Here is my code.
@interface ViewController ()
{
BOOL isImageselected;
UIImageView *myImage;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)addPhotoButton:(id)sender {
[UIView animateWithDuration:0.3 animations:^{
// animation here
self.pickerView.frame = CGRectMake(0.0, 443.0, 320.0, 125.0);
}];
}
- (IBAction)cameraButton:(id)sender {
[UIView animateWithDuration:0.3 animations:^{
// animation here
self.pickerView.frame = CGRectMake(0.0, 568.0, 320.0, 125.0);
}];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (IBAction)uploadImageButton:(id)sender {
[UIView animateWithDuration:0.3 animations:^{
// animation here
self.pickerView.frame = CGRectMake(0.0, 568.0, 320.0, 125.0);
}];
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
myImage.image = chosenImage;
isImageselected = YES;
if (isImageselected == YES) {
myImage = [[UIImageView alloc]initWithFrame:CGRectMake(8.0, 8.0, 95.0, 95.0)];
self.addPhotoButton.frame = CGRectMake(106.0, 8.0, 95.0, 95.0);
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
@end
I think the problem is happening where I am creating the imageView dynamically but I am not getting the point what is wrong.