Reputation: 41
I want to execute some code, before showing another view, when a user pushes the Bar Item with different view in a Tab Bar Controller.
I am trying to use delegation in my class:
@interface HPAAddCarOverallInfoTableViewController () <UITabBarControllerDelegate>
And I get close to my problem by using delegates method:
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
Unfortunately, (UIViewController *)viewController
holds information about selected View Controller and not information about from what View Controller it was selected.
Question: Can You tell me, please. How I can get information which will tell me from what displayed view the Tab Bar Item was pushed?
Upvotes: 2
Views: 1151
Reputation: 124997
You can implement -tabBarController:shouldSelectViewController:
in your tab bar controller delegate. You'll get that message before the new view controller is actually selected, so you can find out what view controller is currently selected, perhaps saving it in an ivar or something. Maybe you can do the work you need to do in that method, or maybe you'll wait until the ...didSelectViewController:
message, but either way you'll know both the old and new view controllers.
Upvotes: 5