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