我为我的 iPad 应用程序使用 UiTabBarController。其中一个选项卡是带有收藏夹的 UITableView。当我单击一个单元格时,我希望收藏夹在另一个选项卡的 viewController 中打开。
我通过在单例中分配一个变量然后通过 [self.tabBarController setSelectedIndex:2] 选择另一个选项卡以丑陋的方式解决了它;
在目标 viewController 上的 ViewWillAppear 中,我从单例中读取值,然后执行所有操作。
必须有适当的方法来做到这一点。如何在另一个选项卡中引用 ViewController 的实例?有没有办法在选项卡中加载另一个 View Controller ?
任何人?
最佳答案
您可以使用 viewControllers 属性获取 Tab View 中的所有 View Controller 。
从文档:
The default value of this property is nil. When configuring a tab bar controller, you can use this property to specify the content for each tab of the tab bar interface. The order of the view controllers in the array corresponds to the display order in the tab bar. Thus, the controller at index 0 corresponds to the left-most tab, the controller at index 1 the next tab to the right, and so on. If there are more view controllers than can fit in the tab bar, view controllers at the end of the array are managed by the More navigation controller, which is itself not included in this array.
关于ios - 如何在另一个选项卡中向 View Controller 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7619456/