Search code examples
iphoneuinavigationcontrolleruitabbarviewwillappear

Detecting if a user switches tabs inside a UITabBar on the iPhone?


Good day,

I am having a little bit of a problem. I want to track user behavior for an app. The app has a tab bar with 5 tabs. Every time a user switches tabs, I'd like to know about it. That's all I want to do.

Which method should I use here?

viewWillAppear/viewDidAppear are not getting called.

A UINavigationController actually puts this UITabBar as the UINavigationController's root view (did I describe that right?). To be very clear, the user launches the app. There are several buttons. If you press one of them, you are taken to that UITabBar with its 5 associated tabs. (In the UITabBar there is a UINavigationBar that will take you to back to the home screen.). How do I get notified when the user presses tab1, tab2, tab3, tab4, tab5--no matter which order or how many times these tabs are pressed?

Do I need a UINavigationController delegate to be implemented? If so, I'm not sure where to put that code. Or is there something simpler?

Thanks!


Solution

  • Look at the UITabBarControllerDelegate protocol. Set your tabBarController's delegate to self (most likely) and implement tabBarController:didSelectViewController:.