【问题标题】:Unable to go back through a navigation controller to a VC of another navigation controller using Swift无法使用 Swift 通过导航控制器返回到另一个导航控制器的 VC
【发布时间】:2016-08-25 10:57:08
【问题描述】:

正如您在下面看到的,notificationsVCTabBarController 的一部分,它嵌入在 navigationContoller 中(我们先称它为 nC)。然后是从notificationsVC 到第二个navigationController 的segue,它将显示messagesVC。

messagesVC 中有一个返回按钮,按下该按钮应返回到 notificationsVC

func backbutton() {        
    navigationController?.popViewControllerAnimated(true)         
}

现在这显然不起作用,因为 navigationController 将获取最近的 NC 并将 VC 弹出它的堆栈,但它不会让我回到 notificationsVC

还有其他选择吗?尽管我也尝试过,但也没有成功。

self.dismissViewControllerAnimated(true, completion: nil);

更详细的视图

另外我正在使用JSQMessagesViewController 库来显示messagesVC 中的消息,这无关紧要,但仍然值得一提。感谢您的宝贵时间!

【问题讨论】:

  • navigationController?.navigationController?.popViewControllerAnimated(true) 从 NavigationController 的 NavigationController 弹出视图。

标签: ios swift uinavigationcontroller storyboard popviewcontroller


【解决方案1】:

您可以通过从 TabBarViewController 中询问来访问第一个 NavigationViewController,如下面的代码所示:

tabBarController?.navigationController?.popViewControllerAnimated(true)

还向您询问第二个导航控制器的导航控制器应该可以工作:

navigationController?.navigationController?.popViewControllerAnimated(true)

【讨论】:

    【解决方案2】:

    您的导航控制器只有一个 VC,即 MessagesVc。因此,当您弹出它时,导航控制器的堆栈中没有其他 VC 可以呈现。您的 NotificationsVC 不在导航控制器的堆栈中。

    所以我建议你在点击后退按钮时这样做:

    tabBarController?.selectedIndex = Index_Of_NotificationsVC

    【讨论】:

      【解决方案3】:

      试试:-

      let nVC = self.navigationController?.tabBarController?.navigationController?.storyboard?.instantiateViewControllerWithIdentifier("NotificationStoryboardVC_ID") as! NotificationVC
      
      navigationController?.tabBarController?.navigationController?.pushViewController(nVC, animated: true)
      

      【讨论】:

      • NotificationStoryboardVC_ID 和我们在属性检查器中设置的一样吧?而且 pushViewController 不会接受字符串。
      • 我的错...;),我已经编辑了答案,但我猜你已经尝试过了?
      猜你喜欢
      • 2020-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-12
      • 2020-05-27
      • 1970-01-01
      • 2018-02-16
      相关资源
      最近更新 更多