presentViewController:imagePickerController正在弹出我的navigationController?

时间:2013-08-18 04:34:15

标签: iphone ios ios6 uinavigationcontroller uiimagepickercontroller

我正在使用presentViewController:imagePickerController来显示UIImagePickerController。出于某种原因,当我最终解雇该控制器时,我的原始导航控制器丢失了它的堆栈,我的应用程序又返回到根视图控制器。

我正在记录self.navigationController.viewControllers,我可以看到在运行presentViewController:imagePickerController行之后,我的导航控制器会丢失除根控制器之外的所有控制器。

 UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
 imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
 imagePickerController.sourceType = sourceType;
 imagePickerController.delegate = self;
 imagePickerController.navigationBarHidden = YES;

 self.imagePickerController = imagePickerController;

DLog(@"self.navigationController:%@",self.navigationController.viewControllers);
[self.navigationController presentViewController:imagePickerController animated:YES completion:^{
        DLog(@" after presenting self.navigationController:%@",self.navigationController.viewControllers);

    }];

////关闭它

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    DLog(@"self.navigationController:%@",self.navigationController.viewControllers);
    [self.navigationController dismissViewControllerAnimated:YES completion:^{

    }];
}

/////我的NC设置在哪里

OFMainViewController *mainController = [[OFMainViewController alloc]init];
    mainController.managedObjectContext = self.managedObjectContext;
    navigationController = [[UINavigationController alloc]initWithRootViewController:mainController];
[self.window setRootViewController:navigationController];

2 个答案:

答案 0 :(得分:1)

使用self来解除和调用imagepickerviewcontroller,而不是使用self.navigationController。

答案 1 :(得分:0)

您应该在imagePickeController而不是self上展示self.navigationController

[self presentViewController:imagePickerController animated:YES completion:^{
    DLog(@" after presenting self:%@",self.navigationController.viewControllers);

}];

并相应地驳回它:

////Closing it

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    DLog(@"self.navigationController:%@",self.navigationController.viewControllers);
    [self dismissViewControllerAnimated:YES completion:^{

    }];
}
相关问题