我在尝试从一个 UINavigationController 推送到另一个 UINavigationController 时遇到问题。
我到达了我的 CameraViewController - 通过在不同的 View Controller 中选择一个按钮来嵌入 UINavigationController,如下所示:
- (void)goToCamera {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
CameraViewController *camera = [storyboard instantiateViewControllerWithIdentifier:@"CameraView"];
[self presentViewController:camera animated:YES completion:^{
}];
}
从那里,我尝试通过推送到我的 PublishViewController - 它没有嵌入 UINavigationController,因为我认为如果来自另一个 UINavigationController,则不需要它。
我尝试这样做:
- (void)goToPublish {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
PublishViewController *publishView = [storyboard instantiateViewControllerWithIdentifier:@"PublishView"];
[self.navigationController pushViewController:publishView animated:YES];
}
有什么想法为什么这不起作用吗? Controller 从不插入。当我最初使用相机时嵌入仍然有效,还是我还需要初始化 UINavigationController?
这是我的 Storyboard:
最佳答案
当您呈现一个名为 VC1 的 viewController 时,除非您呈现一个 navigationController,否则 VC1 的 navigationController 必须为 nil。
你应该知道,当有人(UINavigationController)推送它时,vc.navigationController不是nil,或者它是UINavigationController的rootViewController。(事实上,nav的rootViewController也被推送到nav的堆栈中)。
您应该创建一个新的 navigationController。
- (void)goToCamera {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
CameraViewController *camera = [storyboard instantiateViewControllerWithIdentifier:@"CameraView"];
UINav *nav = UINav alloc]initWithRootVC:camera];
[self presentViewController:nav animated:YES completion:^{
}];
}
关于ios - 推送问题 UINavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27895074/