提出视图控制器

时间:2014-05-09 02:03:43

标签: ios objective-c ios7

我在使用此代码拍照后呈现一个表格视图控制器:

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

但是当我跑步并拍摄照片并尝试呈现CCcameraviewController后,我收到此终止错误:

  

由于未捕获的异常而终止应用   'NSInvalidArgumentException',原因:'应用程序试图呈现一个   nil模态视图控制器在目标上。'

2 个答案:

答案 0 :(得分:0)

应该是

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

self.navController而非self.viewController

答案 1 :(得分:0)

您应首先设置self.viewController。像这样:

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