ios - 推送不适用于以模态方式呈现的 Controller

标签 ios swift segue uistoryboardsegue

你好,我在 FirstViewController 上有一个按钮,我将一个 segue 从 firstViewController 拖到 secondViewController 作为 segue Modally。现在在 secondViewController 上我以编程方式生成一个 Button 并继续第三个 Controller 我正在插入 Controller (segue Push)但它不起作用。第三个 Controller 没有出现。单击自定义按钮时没有任何反应。

这是第二个ViewController的代码

 func nextButtonClicked(sender:UIButton!){
    let takeProductPhotoController = self.storyboard!.instantiateViewControllerWithIdentifier("takeProductPhotoController") as! TakeProductPhotoController
            takeProductPhotoController.trip = trip
            self.navigationController?.pushViewController(takeProductPhotoController, animated: true)
}

注意:我不需要第二个 View Controller 上的 NavigationBar,因此在以模态方式呈现它时它没有显示 navigationBar。但我需要第三个导航栏。这就是我插入 naviagtioncontroller 的原因

最佳答案

  • 每当你想从弹出的 Controller 中推送时,你必须创建 新的 NavigationController 并且还设置了你的 ViewController 想要将模态呈现为 navigationControllerrootViewController
  • 当我们想以模态方式呈现SecondViewcontroller时,我们正在呈现 rootViewController 设置为 SecondViewController 的导航 Controller 。所以我们 已经创建了新的导航堆栈。之后我们要 将 Controller 推送到在呈现 SecondViewController 时创建的新导航堆栈中。

1) 你的代码应该是这样的 在 FirstViewController

let secondViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("aIdentifier") as! SecondViewController 
    let nav = UINavigationController(rootViewController: SecondViewController )
    self.presentViewController(nav, animated:true, completion:nil)

2) 从 secondViewController 你可以将 ThirdViewController 插入 self.naviagtionController。 在 SecondViewController 中的 Button Action 中编写以下代码

let thirdViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("cIdentifier") as! ThirdViewController self.navigationController?.pushViewController(thirdViewController , animated: true)}

关于ios - 推送不适用于以模态方式呈现的 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35370683/

相关文章:

ios - 如何使用 beginBackgrounTaskWithExpirationHandler 有选择地指定在后台执行的内容 :

objective-c - 获取 UIGestureRecognizer 的 UITouch 对象

ios - 自定义字体不能以编程方式在 Swift 中工作,但可以与 xib/Storyboard 一起工作

iphone - 准备继续传递数据选择器

ios - 单击按钮时相同的 View Controller 加载两次

ios - 在函数内将数据传递到 segue.destination 时出现问题

IOS预期表达式错误

ios - 如何使用 URL Swift 3 下载图像?

swift - 弱小的自己去哪儿了?

swift - UIPageViewControllers UIPageControl 在转换过程中出现故障