关闭UIImagePickerController

时间:2013-05-10 05:05:07

标签: ios objective-c uiimagepickercontroller

我已经尝试过解除UIImagePickerController的所有变种,但没有运气。我做错了什么。

- (IBAction)choosePhoto
{
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.delegate = self;
    self.picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:self.picker animated:YES];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePicker
{
    NSLog(@"dismiss image picker");
    [self dismissModalViewControllerAnimated:NO];
    [[self.picker parentViewController] dismissModalViewControllerAnimated:NO];
    [self.presentedViewController dismissModalViewControllerAnimated:NO];
    [self.presentingViewController dismissModalViewControllerAnimated:NO];
     // And every other way i could think of
}

- (void)imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    .. same stuff here
}

我试图从父,祖父母,navigationController和根控制器呈现选择器,但没有任何作用。我做什么我不能解雇ImagePickerController。

请注意每次调用日志语句。

干杯

4 个答案:

答案 0 :(得分:9)

试试这一行。它可能适合你。

[self.picker dismissModalViewControllerAnimated:NO];

对于 iOS 6 以及稍后使用此

[self.picker dismissViewControllerAnimated:NO completion:nil];

也可以使用此代码来展示您的选择器控制器

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)]){
    [self presentViewController:self.picker animated:YES completion:nil];
} else {
    //To target iOS 5.0
    [self presentModalViewController:self.picker animated:YES];
}

答案 1 :(得分:6)

你在运行iOS 6吗?如果是这样,则{@ 1}}已弃用,可能会导致一些意外结果。请尝试使用presentModalViewController:

但从技术上讲,这就是你应该做的所有事情:

presentViewController:animated:completion:

答案 2 :(得分:5)

对于Swift使用此:

func imagePickerControllerDidCancel(picker: UIImagePickerController!) {
    picker.dismissViewControllerAnimated(true, completion: nil)
}

答案 3 :(得分:2)

对于Swift 4:

func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
        picker.dismiss(animated: true, completion: nil)
}