Accessing a view controller created through Storyboard using the App Delegate

后端 未结 7 1733
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-09 10:41

I\'m working on an iOS5 app using storyboard, and I have a method in a view controller class that i\'d like to access from the App Delegate. The trouble is, this view contr

7条回答
  •  无人及你
    2020-12-09 11:43

    In the AppDelegate, you could simply use indexes to access the controllers via UITabBarController:

    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    firstViewController = [[tabBarController viewControllers] objectAtIndex:0];
    secondViewController = [[tabBarController viewControllers] objectAtIndex:1];
    thirdViewController = [[tabBarController viewControllers] objectAtIndex:2];
    

    Naturally, this will get messed up if you change the ordering of the tab bar. Also, if you're looking for a controller deeper in the hierarchy, you need to do a bit more legwork.

提交回复
热议问题