我尝试过每一种不同的方法来消除一个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。
请注意,每次都会调用日志语句。
干杯
发布于 2013-05-10 13:58:24
尝试这一行。这可能对你有用。
[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];
}
发布于 2013-05-10 13:46:43
您运行的是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
}
发布于 2015-01-12 21:06:59
对于Swift,请使用以下命令:
func imagePickerControllerDidCancel(picker: UIImagePickerController!) {
picker.dismissViewControllerAnimated(true, completion: nil)
}
https://stackoverflow.com/questions/16475506
复制相似问题