Method call when UITabBar is selected?

I'm currently writing an app on an iPhone and I'm just wondering if anyone knows of a way to call a function, but only when a tab is selected.

I have a separate view controller for the corresponding tab and I want to call a function that updates the GPS position when the tab is selected.

If anyone can help, that would be great :)

Thanks - James

+2


source to share


2 answers


It's just that anyone else has this problem, I am instead calling the ' viewDidAppear ' method in the view controller that is associated with the tab.

- (void)viewDidAppear:(BOOL)animated {
    // do stuff here    
}

      



This shower was more perfect for me as I only wanted to check one tab anyway!

+3


source


If you implement the UITabBarControllerDelegate protocol somewhere, you can handle when a tab is clicked if you install a class that implements it as a tab controller delegate. This way, you can call the correct method when you need it. Link here ; the method you probably want is tabBarController: didSelectViewController:



+2


source







All Articles