Mona
Mona

Reputation: 6175

perform a method every time a tab is selected

I have tabview based project. how can I make a view connected to a tab perform a certain method every time the tab is selected?

Please help, Thanks

Upvotes: 2

Views: 98

Answers (2)

dimme
dimme

Reputation: 4424

EDIT: I mistook TabBar for TableView. I'm sorry for that. I let my old answer being here, it might help you in another problem.

The answer that bryamac gave you is the right one.

When you click the tab then you probably load some UIView to display some content. For that UIView you must have a controller class. In that controller class there are - (void)viewDidAppear:(BOOL)animated and - (void)viewWillAppear:(BOOL)animated methods which you may use.

Old answer

What you want to do is make a class to a UITableViewDelegate.

Then you must set this class as the delegate of the UITableView, you can to that in the Interface Builder by right-clicking on the UITableView and dragging its delegate to the class that you have chosen, e.g. its own controller class.

Then you implement this method inside the UITableViewDelegate-class:

– tableView:didSelectRowAtIndexPath;

More information here.

Upvotes: 2

bryanmac
bryanmac

Reputation: 39306

Assuming the tab var is the main way to make the view appear, you can hook code into:

- (void)viewDidAppear:(BOOL)animated

or ...

- (void)viewWillAppear:(BOOL)animated

Upvotes: 2

Related Questions