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”时遇到错误,这是我尝试启动导航控制器的行,该控制器的根视图名为 UIImagePickerController
图像选择器。我不知道我做错了什么?有帮助吗?
错误是:
Terminating app due to uncaught exception
'NSInvalidArgumentException', reason: 'Pushing a navigation controller
is not supported'
听起来您正试图将一个导航控制器推到另一个导航控制器上。您应该改为执行以下操作:
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];
UIImagePickerController 派生自 UINavigationController,这就是为什么您不能将其推送到另一个 UINavigationController(或设置为根视图控制器)的原因。
我正在尝试使用以下代码在 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”时遇到错误,这是我尝试启动导航控制器的行,该控制器的根视图名为 UIImagePickerController
图像选择器。我不知道我做错了什么?有帮助吗?
错误是:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing a navigation controller is not supported'
听起来您正试图将一个导航控制器推到另一个导航控制器上。您应该改为执行以下操作:
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];
UIImagePickerController 派生自 UINavigationController,这就是为什么您不能将其推送到另一个 UINavigationController(或设置为根视图控制器)的原因。