user3000770
user3000770

Reputation: 29

How can I refresh view every time when a tab bar item is clicked?

I have an UITabBarController(empty) which have 2 subView. These two subView are tableView(get data from database). I want to refresh view every time when a tab bar item is clicked(get new data from DB).

I search many method on Internet. Some said use the viewwillappear. But did work.

Can anyone give me some Suggestions? Thanks

Upvotes: 1

Views: 4175

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89559

You set something to be the tab bar controller delegate and when the user clicks on a tab bar item, override:

tabBarController:didSelectViewController:

and each time the item is touched, send a message to the view controller (which is one of the parameters that comes in via that delegate method) to refresh whatever you want.

Don't use "viewWillAppear". That's meant to be called right before the view is meant to appear.

I'd suggest implementing a custom "refreshView:" method (or you can choose whatever method name that makes sense to you) and inside there, do whatever UI refreshing you want to do for the view owned by that view controller.

Upvotes: 2

Related Questions