UIImagePickerController 在第二次取消时崩溃
UIImagePickerController crashes on cancelling second time
我在我的应用程序中使用 UIImagePickerController
,每当我第二次单击取消时它就会崩溃并显示以下崩溃日志:
Terminating app due to uncaught exception
'UIViewControllerHierarchyInconsistency', reason: 'child view
controller: should have parent
view controller:(null) but actual parent is:'
关闭代码:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
相同的代码在其他应用程序中运行良好,但是当我将代码复制到新项目中时,崩溃反复发生。
它发生在 iOS 8.3 和 7.1 上,未在其他版本上测试。
任何帮助将不胜感激。
在 .h
中设置委托
@interface YourViewController : UIViewController < UIImagePickerControllerDelegate, UINavigationControllerDelegate>
当你想打开它时初始化图像选择器。
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.allowsEditing = YES;
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imgPicker animated:YES completion:^{ }];
委托方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
我在我的应用程序中使用 UIImagePickerController
,每当我第二次单击取消时它就会崩溃并显示以下崩溃日志:
Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller: should have parent view controller:(null) but actual parent is:'
关闭代码:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissViewControllerAnimated:YES completion:nil];
}
相同的代码在其他应用程序中运行良好,但是当我将代码复制到新项目中时,崩溃反复发生。 它发生在 iOS 8.3 和 7.1 上,未在其他版本上测试。 任何帮助将不胜感激。
在 .h
@interface YourViewController : UIViewController < UIImagePickerControllerDelegate, UINavigationControllerDelegate>
当你想打开它时初始化图像选择器。
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
imgPicker.delegate = self;
imgPicker.allowsEditing = YES;
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imgPicker animated:YES completion:^{ }];
委托方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}