closuresUIImagePickerController

我已经尝试了任何运气的解雇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 } 

我试图从父母,祖父母,导航控制器和根控制器呈现select器,没有任何工作。 我永远不会解雇ImagePickerController。

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

干杯

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

 [self.picker dismissModalViewControllerAnimated:NO]; 

而对于iOS 6和以后使用这个

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

也使用这个代码来呈现你的select器控制器

 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) }