簡體   English   中英

NavigationController initWithRootViewController使應用程序iOS8崩潰

[英]NavigationController initWithRootViewController crashes app iOS8

我試圖用以下代碼在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”的地方遇到了錯誤,這是我嘗試使用名為imagePicker的 UIImagePickerController的根視圖啟動導航控制器的 我不知道我在做什么錯? 有什么幫助嗎?

錯誤是:

由於未捕獲的異常“ NSInvalidArgumentException”而終止應用程序,原因:“不支持按下導航控制器”

UIImagePickerController派生自UINavigationController,這就是為什么您不能將其推送到另一個UINavigationController(或設置為根視圖控制器)的原因。

聽起來您正在嘗試將導航控制器推到另一個導航控制器上。 您應該改為執行以下操作:

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];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM