Access to General UITabBarController properties fr

2020-04-30 17:55发布

问题:

I'll describe what I want to do. I have Login page(ViewController).

After I login I pass to UITabBarController - MainTabBar.m. This MainTabBar has 'key' property, which gets the user key from the login page.

The UITabBarController has 2 tabs - Tab1.m, Tab2.m.

I want to access the MainTabBar propery from each tab.

How I do this?

Thanks!

回答1:

Assuming that Tab1 and Tab2 are UIViewController subclasses you can access the key property in either Tab1.m or Tab2.m as:

#import MainTabBar.h
//...//

// Getting the parent TabBarController
MainTabBar *parentTabBarController = (MainTabBar *)self.tabBarController;

// Getting the key property from the parent TabBarController
NSString *theUserKey = parentTabBarController.key;

Hope it helps!