【问题标题】:NavigationController initWithRootViewController crashes app iOS8NavigationController initWithRootViewController 使应用程序 iOS8 崩溃
【发布时间】:2015-07-22 19:18:03
【问题描述】:

我正在尝试使用以下代码在 UINavigationController 中显示 UIImagePickerController

UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.showsCameraControls = NO;
imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.tabBarController.tabBar.hidden = YES;

NSLog(@"HERES THE self.peresntingviewcontorller:: %@", self.presentingViewController);

//[self presentViewController:imagePicker animated:YES completion:^{}];
UINavigationController *cameraNavigationController = [[UINavigationController alloc] initWithRootViewController:imagePicker];  //ERROR HERE
[self presentViewController:cameraNavigationController animated:YES completion:nil];

但我在添加注释“//ERROR HERE”时遇到错误,我尝试在该行中使用名为 imagePickerUIImagePickerController 的根视图启动导航控制器.我不知道我做错了什么?有什么帮助吗?

错误是:

由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'推导航控制器 不支持'

【问题讨论】:

  • 这段代码在哪里运行,self的类型是什么?
  • 我刚刚发现显示 imagePicker 的视图控制器已经在 UINavigationController 中,因此我无法在顶部显示新的 navController.. >Apple 不允许堆叠导航控制器
  • 你在用模拟器吗? UIImagePickerControllerSourceTypeCamera 仅在 iOS 设备中的模拟器中不受支持。对于模拟器,您可以使用UIImagePickerControllerSourceTypePhotoLibrary 进行测试

标签: ios uinavigationcontroller


【解决方案1】:

UIImagePickerController 是从 UINavigationController 派生的,这就是为什么不能将它推送到另一个 UINavigationController(或设置为根视图控制器)的原因。

【讨论】:

  • 谢谢。我在这里真的很困惑。
【解决方案2】:

听起来您正试图将导航控制器推送到另一个导航控制器上。你应该这样做:

UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.showsCameraControls = NO;
imagePicker.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.tabBarController.tabBar.hidden = YES;

[self presentViewController:imagePicker animated:YES completion:nil];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多