简体   繁体   English

在不同导航控制器中的选项卡栏控制器屏幕之间导航

[英]Navigating between tab bar controller screens in different navigation controllers

First of all sorry if I'm explaining this badly, I've re-read my question several times and I can't figure out how a great way to explain the problem. 首先,很抱歉,如果我对这个问题的解释不好,我已经多次阅读了我的问题,但我想不出如何很好地解释问题的方法。 Please let me know if you have any other questions... 如果您还有其他疑问,请告诉我...

My app has a layout that requires the screens to be embedded in both a tab bar controller and navigation controller. 我的应用程序的布局要求屏幕必须同时嵌入标签栏控制器和导航控制器中。 I've got it set up so that it works for the most part, however I'm running into some problems navigating from one navigation controller/tab to another - I have one navigation controller for one tab (where the user selects an image to upload), and a second navigation controller for the screens in the second tab. 我已经对其进行了设置,以便可以在大多数情况下使用,但是我遇到了从一个导航控制器/选项卡导航到另一导航卡/选项卡时遇到的一些问题-我为一个选项卡使用了一个导航控制器(用户可以在其中选择图片上传),以及第二个标签中屏幕的第二个导航控制器。 Here is what it looks like in storyboard: 这是情节提要中的外观:

在此处输入图片说明

The problem I have is that once the user selects a photo to post in the "upper" navigation controller (the "right" tab) and hits "post", I navigate to the newly updated feed (which is within the other tab) with: 我遇到的问题是,一旦用户选择要在“上部”导航控制器(“右侧”标签)中发布的照片​​并点击“发布”,我就会导航到新更新的提要(位于其他标签中) :

                let feedController = self.storyboard?.instantiateViewController(withIdentifier: "feedVC") as! FeedViewController
                feedController.navigationItem.setHidesBackButton(true, animated: false)
                self.navigationController?.pushViewController(feedController, animated: true)

And while the screen and updated feed appear correctly, I am still within the "right" tab, when the feed should be in the "left" tab. 虽然屏幕和更新的提要正确显示,但当提要应位于“左”选项卡中时,我仍位于“右侧”选项卡中。

My question is, how do I correctly navigate to the other navigation controller, and be put back within the correct tab? 我的问题是,如何正确导航到另一个导航控制器,然后将其放回正确的选项卡中?

You can switch tabs instead of pushing a new view controller onto the current tab's navigation stack using tabBarController?.selectedIndex = 0 . 您可以使用tabBarController?.selectedIndex = 0切换选项卡,而不是将新的视图控制器推送到当前选项卡的导航堆栈中。 This should take you back to the original feed page with no need for any of the push code. 这将带您回到原始提要页面,而无需任何推送代码。

In order to update it with the new post, you'll need to refresh the data when it appears by overriding the view controller's viewWillAppear method to re-fetch the data and reload the collection view. 为了用新帖子更新它,您需要通过重写视图控制器的viewWillAppear方法刷新数据,以重新获取数据并重新加载集合视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 标签栏控制器中的导航控制器 - Navigation Controllers in tab bar controller 在标签栏控制器中访问多个导航控制器 - accessing multiple navigation controllers in a tab bar controller 在导航控制器之间导航时导航栏不显示标题 - Navigation Bar not showing Title when navigating between navigation controllers 在标签栏元素中导航时,未调用导航控制器 - when navigating through tab bar elements, navigation controller is not called 控制器之间的导航-黑屏 - Navigation between Controllers - Black Screens 如何在故事板的标签栏上启动导航控制器的第三个视图控制器 - how to start third view controller of navigation controllers on tab bar in storyboard iOS 7:标签栏控制器的不同导航项 - iOS 7: different navigation items for tab bar controller 在视图控制器->标签栏控制器->导航控制器->视图控制器的层次结构内旋转视图控制器 - Rotating view controllers within a hierarchy of View Controller -> Tab Bar Controller -> Navigation Controller -> View Controller 如何在带有Tab Bar Controller的View Controller之间传输浮点值? - How to transfer a float value between View Controllers with Tab Bar Controller? 在视图控制器和标签栏控制器之间传递数据 - Passing data between view controllers and tab bar controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM