【问题标题】:Swift: Show a navigation bar/top bar on modal view with delegateSwift:在带有委托的模态视图上显示导航栏/顶部栏
【发布时间】:2016-11-03 22:55:51
【问题描述】:

我正在尝试强制导航栏显示在模态视图上。根据this answer,我试图通过将模态视图nextScreenViewController 嵌入到一个特殊的导航控制器nextScreenNavigationController 中。

但是,我使用委托模式在初始 viewController 和 nextScreenViewController 之间传递数据。在嵌入 navigationController 之前,我使用以下代码进行初始化:

override func prepareForSegue(segue: UIStoryboardSegue, sender:   AnyObject?) {
     if segue.identifier == "goToNextScreen" {      
         let nextScreenDelegate = segue.destinationViewController as! nextScreenViewController
          nextScreenDelegate.delegate = self
     }
}

Some research 建议,为了说明nextScreenNavigationController 我应该使用类似...的代码

 override func prepareForSegue(segue: UIStoryboardSegue, sender:   AnyObject?) {
      if segue.identifier == "goToNextScreen" {
          let navigation: UINavigationController = segue.destinationViewController as! nextScreenNavigationController
          var nextScreenDelegate = nextScreenViewController.init()
          nextScreenDelegate = navigation.viewControllers[0] as! nextScreenViewController
          nextScreenDelegate.delegate = self
  }
}

但是,这会失败而不会崩溃 - 没有数据传递。

如果您想要更多我的委托模式,请发表评论...我只是想确定这不是一个基本的实现问题。或者,有没有更好的方法在模态视图上显示导航栏?

【问题讨论】:

    标签: swift uinavigationcontroller modal-dialog uikit


    【解决方案1】:

    对不起 - 没关系!我意识到上面的代码有效,我的问题是我未能在故事板中为 navigationController 分配 nextScreenNavigationController 类。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 2023-03-10
      • 2011-06-03
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      相关资源
      最近更新 更多