UIImagePickerController, application exit when clicking cancel button on right top of photo album screen on selecting a image
UIImagePickerController, application exit when clicking cancel button on right top of photo album screen on selecting a image.
-(void) getImageAction:(id) sender
{
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
if([sender tag] == 0)
{
if (![[UIDevice currentDevice].model isEqualToString:@"iPhone Simulator"] && ![[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"]) {
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}
else {
NSLog(@"Camera Not available in your device");
return;
}
}
else
{
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
[self presentModalViewController:imagePickerControlle开发者_Python百科r animated:YES];
}
#pragma mark -
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
NSLog(@"image picker method called");
// Dismiss the image selection, hide the picker and show the image view with the picked image
[imagePickerController dismissModalViewControllerAnimated:YES];
//imagePickerController.view.hidden = YES;
CGRect frame = CGRectMake(40, 5, 200, 200);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:frame];
imageView.image = image;
imageView.hidden = NO;
[self.view addSubview: imageView];
[self.view addSubview: messageText];
[self.view addSubview: sendGreet];
[fromGallery removeFromSuperview];
[fromCamera removeFromSuperview];
}
I, your method -(void) getImageAction:(id) sender
add [imagePickerController release];
in the end. When ever you are using presentModalViewController
, you got to release the controller you are moving to.
In general the application crashes when there is a memory leak or unknown identifier send to some method.
Hope this works for you!!
精彩评论