【问题标题】:How to get pointer of storyboard UITabBarController in AppDelegate如何在 AppDelegate 中获取情节提要 UITabBarController 的指针
【发布时间】:2014-10-08 16:46:39
【问题描述】:
我正在使用情节提要来创建我的应用程序。我的应用程序的根目录是一个 UITabBarController。如何从我的应用程序委托中访问我的tabBarController?我设法从我的一个 UIViewControllers 中成功地实现了这些操作。但我想将代码移动到我的应用程序委托。我怎么能做到这一点?我以为我可以从故事板拖放到我的应用程序委托并获得类似
@property (nonatomic, strong) IBOutlet UITabBarController *tabBarController;
但这似乎不是目前的选择。
【问题讨论】:
标签:
ios
storyboard
xcode5
uitabbarcontroller
appdelegate
【解决方案1】:
将该代码带到 AppDelegate 似乎不是一个好主意,但如果您想这样做,您可以在 AppDelegate 中添加一个弱属性并从您的 UITabBarController 设置该属性。
在 ApplicationDelegate 中:
@property (nonatomic, weak) MyTabBarController *tabController;
在 MyTabBarController awakeFromNib 方法中:
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
delegate.tabController = self;
【解决方案2】:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;