简体   繁体   中英

iPhone SDK: How can I determine the last active tab in a TabBarController?

One of the tab bar controller tabs in my iPhone app changes what it displays based on where the user arrived from (which other tabs). For example, if the tabs are A, B, C and D, the C tab will display a picture if the user was previously on tab A, but text if the user was previously on tab B.

I'm not sure how to implement this without subclassing the TabBarController (which Apple documentation discourages). TabBarController has a property for currently active controller, and a list of all controllers in the tab bar, but no way to see the 'tab bar controller traversion tree/stack', so to speak. Any thoughts?

Instead of subclass UITabBarController you can set a delegate and keep track of the last selected view controller via

- (void)tabBarController:(UITabBarController *)tabBarController
    didSelectViewController:(UIViewController *)viewController;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM