ios - 推送问题 UINavigationController

标签 ios objective-c storyboard

我在尝试从一个 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:

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/

相关文章:

ios - 随机扫描每个坐标

iphone - 防止在越狱设备上购买假冒应用程序

ios - 从文件管理器加载时 UIImage 自动旋转

ios - 适用于不同 iPhone 尺寸的多个 Storyboard

ios - 室内导航如何使用 iBeacon 在 iOS 中工作?

ios - 如何检测 scrollView 的滚动方向?

html - 网站无法在移动设备上正确显示

ios - 几天后正在测试的 iPhone 应用程序崩溃

ios - 通过访问 AppDelegate 中的 Tab Bar Items 更改 Tab Bar Item Image inset

swift - 呈现 activityViewController 时 UINavigationBar 隐藏