如何在didFinishSavingWithError之后解除图像选择器?

时间:2012-04-12 10:34:57

标签: ios uiimagepickercontroller

我想要做的就是在警报显示图片已经或未被保存后,应该解雇选择器,但我无法找到方法。

我像这样呈现图像控件:

[self presentModalViewController:imagePicker animated:YES];

我知道我需要dismissmodalviewcontroller,因为我是为取消案例做的,但我不知道放在哪里,以便在图像保存后它存在。

- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

        UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
    }

- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    UIAlertView *alert;

    // Unable to save the image  
    if (error)
        alert = [[UIAlertView alloc] initWithTitle:@"Error" 
                                           message:@"Unable to save image to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    else // All is well
        alert = [[UIAlertView alloc] initWithTitle:@"Success" 
                                           message:@"Image saved to Photo Album." 
                                          delegate:self cancelButtonTitle:@"Ok" 
                                 otherButtonTitles:nil];
    [alert show];
}

2 个答案:

答案 0 :(得分:1)

您必须在本地创建UIImagePickerController实例,并在alertview委托方法中,只需将其解除。

答案 1 :(得分:0)

这取决于你如何使用dismissviewcontrolleranimated呈现uiimagepickercontroller:然后使用dismissModalViewControllerAnimated: