简体   繁体   中英

How to know which was my previous tab bar view controller in iOS?

Say i have 4 tab bar view controllers. I am programatically coming to 2nd tab bar view controller after doing a function in 3rd tab bar view controller. How can i know am coming from 3rd tab bar view controller when i reach 2nd tab bar view controller?

You could easily track that via the UITabBarControllerDelegate methods:

For example, you could implement tabBarController:shouldSelectViewController: and check the tab bar controller's selectedIndex or selectedViewController properties (which will still contain the old value, because that method is called before the change).

Alternatively, you could just implement tabBarController:didSelectViewController: and keep track of the last selected view controller/index yourself.

Keep in mind, though, that both methods are only called for user-initiated tab changes, not those done programmatically.

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