Where to put code that needs to be executed every time a Tableview (tab bar item) is selected
I would like to fill an array from a file every time one of my tableview's is selected开发者_C百科 in the tab bar.
I dont think putting the code in the viewDidLoad method works, because the view gets loaded on once?
Where should the code be placed?
Within the viewDidAppear method?
Put it in viewWillAppear if you want the code to run before the view is displayed.
You can conform to the UITabBarDelegate
protocol and implement the following method:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
I suggest that you set the tag
property in the creation of your UITabBarItem
s in order to differentiate between which tab the item
is.
精彩评论