[英]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.