繁体   English   中英

关闭UIImagePickerController

[英]Dismiss 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。

请注意每次都会调用log语句。

干杯

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

[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];
}

你在运行iOS 6吗? 如果是这样, presentModalViewController:已被弃用,可能会导致一些意外结果。 尝试使用presentViewController:animated:completion:相反。

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

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)imagePicker
{
   [imagePicker dismissViewControllerAnimated:NO completion:nil];//Or call YES if you want the nice dismissal animation
}

对于Swift使用此:

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

对于Swift 4:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM