Reputation: 833
My application uses UITabBarController with 4 tabs. Each tab will have a UIWebView along with other types of objects. When the app launches I need to call the method for this first webView to retrieve my web content.
I have this method in my viewdidLoad: [self performSelectorInBackground:@selector(getAdvisory) withObject:nil];
The web content on the first tab works fine. I'm just at a loss to get my other tabs to load up. I think I would use a switch or if statement but I do not know how to tell which view is loaded.
I need to do the same for the rest of the tabs. The app has a single view controller. When setting an action using a button everything works fine. I just do not know how to call the method when a different view (tapping tabs) loads.
Also when retrieving data from the network, what are the best methods to use to not tie up the main thread? I have read where NSOperation would be used in this scenario. Is this correct? If so how would I go about doing this?
Thanks in advance.
Upvotes: 0
Views: 448
Reputation: 83
I was looking for a solution to this problem and there is a better method.
Simply override the viewDidAppear method and insert the code you want to execute when the view does appear!
As an example the following code will call myMethod.
-(void) viewDidAppear:(BOOL)animated {
[self MyMethod];
}
Upvotes: 1
Reputation: 7427
maybe by using a user delegate of your UITabBar and the method:
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
Sent to the delegate when the user selects a tab bar item.
See reference.
Upvotes: 0