简体   繁体   English

呈现视图控制器

[英]Presenting view controller

I am presenting a table view controller after taking a picture with this code: 我用此代码拍照后呈现了一个表视图控制器:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    // NSLog(@"didFinishPickingMediaWithInfo");

    [self.tabBarController dismissViewControllerAnimated:NO completion:nil];


    NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];

    if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {

        self.image = [info objectForKey:UIImagePickerControllerOriginalImage];
        if (self.imagePicker.sourceType == UIImagePickerControllerSourceTypeCamera) {

            NSLog(@"A photo was taken!");



            CCCameraViewController *viewController = [[CCCameraViewController alloc] initWithImage:self.image];
            [viewController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];

            [self.navController setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
            [self.navController pushViewController:viewController animated:YES];

            self.navController.navigationBar.tintColor = [UIColor blueColor];

            viewController.tableView.tintColor = [[UIColor alloc] initWithRed:49.0 / .0 green:.0 / .0 blue:.0 / .0 alpha:1.0];



            [self.tabBarController presentViewController:self.viewController animated:YES completion:nil];

But when I run and after I take the picture and try to present CCcameraviewController , i get this termination error: 但是当我跑步并拍照后尝试呈现CCcameraviewController ,出现此终止错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target .' 由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'应用程序试图在目标上呈现nil模态视图控制器。

Should be 应该

[self.tabBarController presentViewController:self.navController animated:YES completion:nil];

It's self.navController not self.viewController self.navControllerself.viewController

you should set self.viewController first. 您应该先设置self.viewController Like this : 像这样 :

CCCameraViewController *viewController = [[CCCameraViewController alloc] initWithImage:self.image];
self.viewController = viewController;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM