首页 > 解决方案 > 从已经呈现的 UIViewController 呈现 UIImagePickerController

问题描述

我创建了一个设置/编辑类型的视图控制器,如下所示:

    EditViewController *editController = [storyboard instantiateViewControllerWithIdentifier:@"parent"];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:editController];
    editController.delegate = self;
    navController.modalPresentationStyle = UIModalPresentationPopover;
    [self presentViewController:navController animated:YES completion:nil];

注意:EditViewController 是 UITableViewController 的子类,'self' 只是主导航视图控制器。

现在从这个呈现的导航控制器/视图控制器中,有一个 UIImageView 用户可以选择通过从相机拍摄照片来填充,他们通过按钮操作来完成:

- (IBAction)takePhotoForImageView:(UIButton *)sender {    
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.allowsEditing = YES;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
    picker.modalPresentationStyle = UIModalPresentationFullScreen;

    [self showViewController:picker sender:self];
//    [self presentViewController:picker animated:YES completion:nil];
}

代码运行没有崩溃,但我在调试器中得到以下信息:

[Camera] Failed to read exposureBiasesByMode dictionary: Error Domain=NSCocoaErrorDomain 
Code=4864 "*** -[NSKeyedUnarchiver _initForReadingFromData:error:throwLegacyExceptions:]: data
 is NULL" UserInfo={NSDebugDescription=*** -[NSKeyedUnarchiver
 _initForReadingFromData:error:throwLegacyExceptions:]: data is NULL}

[Presentation] Attempt to present <UIImagePickerController: 0x11d00fe00> on 
<UINavigationController: 0x11e009c00> (from <EditViewController: 0x11d010c00>) 
while a presentation is in progress.

我不知道第一个错误,但假设它与第二个有关。

至于第二个错误/警告(?),在呈现 UIImagePickerController 之前关闭第一个呈现的控制器不是一个选项。

所以问题是:从另一个视图控制器中启动 UIImagePickerController(源类型为 UIImagePickerControllerSourceTypeCamera)的正确方法是什么?

标签: iosobjective-cswiftuiimageviewuiimagepickercontroller

解决方案


推荐阅读