2

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?

1 Answers1

5

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.

Caleb
  • 124,013
  • 19
  • 183
  • 272
  • 1
    Thank You for Your reply! I have to know information about current Tab Bar. I guess, the best way as you mentioned - is to store information about previously selected Tab Bar. Because, as I can see, delegates methods can provide you only with information about selected Tab Bar and not with previously selected Tab Bar. – Vad Vorobjov Nov 06 '14 at 18:16