开发者

Access viewcontroller which resides inside a Tab Bar

开发者 https://www.devze.com 2022-12-24 05:43 出处:网络
I\'m trying to access it in my AppDelegate by doing this Course *rootController = (Course *)[navigationController tabcontroller];

I'm trying to access it in my AppDelegate by doing this Course *rootController = (Course *)[navigationController tabcontroller];

but it won't work doesnt seem to get the "Course" ro开发者_运维技巧ot controller.

Thanks


It is not clear from your question how you have your views arranged and what you are trying to achieve. Usually a UITabBarController contains an array of root view controllers. Each view controller corresponding to a tab on the tab bar. Any or all of those view controllers could be a UINavigationController which itself can contain a stack of view controllers.

UITabBarController
                 |-UINavigationController -> [AViewController,.....]
                 |-UINavigationController -> [AnotherViewController,.....]
                 |-UINavigationController -> [AndAnotherViewController,.....]

The navigation controllers which in this case would be the root view controller for each tab can be accessed via the UITabBarController viewControllers property:

NSArray *rootViewControllers = [tabBarController viewControllers];

So if you want the root view controller of the first tab bar:

UINavigationController *rootViewController = [rootViewControllers objectAtIndex:0];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号