UIImagePickerController,在选择图像时单击相册屏幕右上方的取消按钮时应用程序退出

时间:2011-03-29 09:43:29

标签: iphone xcode uiimagepickercontroller

UIImagePickerController,在选择图像时单击相册屏幕右上方的取消按钮时应用程序退出。

-(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:imagePickerController 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];

}

1 个答案:

答案 0 :(得分:0)

我,您的方法-(void) getImageAction:(id) sender最后添加[imagePickerController release];。当你使用presentModalViewController时,你必须释放你要移动的控制器。

通常,当存在内存泄漏或未知标识符发送到某个方法时,应用程序崩溃。

希望这对你有用!!