解雇的UIImagePickerController(Dismiss UIImagePickerCo

2019-09-02 10:44发布

我曾尝试解雇一个用的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。

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

干杯

Answer 1:

试试这条线。 它可能为你工作。

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


Answer 2:

你在运行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
}


Answer 3:

对于斯威夫特使用:

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


Answer 4:

对于斯威夫特4:

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


文章来源: Dismiss UIImagePickerController