【问题标题】:presentViewController:imagePickerController is popping my navigationController?presentViewController:imagePickerController 弹出我的导航控制器?
【发布时间】:2013-08-20 04:24:06
【问题描述】:

我正在使用 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];

【问题讨论】:

  • 是否有任何东西充当导航控制器的代表?您是否在任何地方明确更改导航堆栈?

标签: iphone ios ios6 uinavigationcontroller uiimagepickercontroller


【解决方案1】:

您应该在self 上显示imagePickeController 而不是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:^{

    }];
}

【讨论】:

    【解决方案2】:

    不要使用 self.navigationController 使用 self 来关闭和调用 imagepickerviewcontroller。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-07
      • 1970-01-01
      • 2014-06-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-27
      • 2012-02-08
      相关资源
      最近更新 更多