ios - 我无法访问 tabbarcontroller 下的 View Controller

标签 ios objective-c uinavigationcontroller interface-builder uitabbarcontroller

我有一个带有 3 个 subview 的 tabbarcontroller。在 IB 中,我将 3 个导航 Controller 连接到 tabbarcontroller,然后我连接到每个导航 Controller ,一个 tableviewcontroller。我有我想从根 tabviewcontroller 设置的公共(public)属性。

我的问题是.. 1)这是设置层次结构的正确方法吗?我听说你不应该在导航 Controller 中嵌入 tabbarcontroller,所以我为我需要的每个 tableviewcontroller 制作了 3 个导航 Controller 。

2) [AITBC 描述] 为空:/

NSArray *viewControllers = [self.tabBarController viewControllers];
AllItemTableViewController *AITBC = (AllItemTableViewController *)[viewControllers[0] rootViewController]; //[viewControllers[0] should be the first navigation controller, so I want its root view controller right?
AITBC.AllGroomedItemsArray = self.allGroomedData;

最佳答案

你不能访问你的 View Controller 的原因是因为你甚至没有将你的 tabBarController 链接到某种代码以便你继续做一些时髦的事情。

要将界面构建器的 tabBarcontroller 链接到您的代码,只需创建您自己的 TabBarViewController 类,将其称为 MyTabBarViewController,然后将该类链接到界面构建器文件中的 TabBarViewController。

完成后,您将能够从新类访问标签栏 View Controller 。

或者您可以通过代码完成此操作,您可以在您的应用委托(delegate)中添加一个 tabBarViewController 属性,然后将 windows.rootViewcontroller 链接到该属性以在您的界面生成器中访问您的 tabBarViewcontroller,而无需在 IB 中直接链接任何内容。但是,正如对话聊天线程中所讨论的那样,您对在您的应用委托(delegate)中包含任何代码表现出不感兴趣。

你也有 [self.tabBarController viewControllers] 而你可以用 self.viewControllers 代替。

关于ios - 我无法访问 tabbarcontroller 下的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21007818/

相关文章:

ios - 在 Objective-C 中制作一个带有排名的计时器

ios - 文本字段被键盘隐藏

ios - 在动画其标题背景时单击 UIButton 显示错误行为

ios - ViewWillAppear 未在选项卡栏项目 View Controller 中调用

ios - 使用 Google iOS SDK 创建多个标记

ios - GCDAsyncSocket 委托(delegate)调用不起作用

ios - 如何在 ios 的标签栏 Controller 中添加搜索栏?

ios - 从斯坦福 iOS 类(class)中收到错误,但我的代码似乎相同

ios - 以编程方式创建导航 Controller 时黑屏

iOS Present Viewcontroller 出现黑屏