Showing ActitivyIndicator when loading data
I have a TabBarApplication and in one view I load XML-data from an URL.
When I click the tab which shows the view with the UITableView and the data received from the XML I would like to show a Activity indicator.
What is recommended here? Should I push a view just for showing the activity indicator. Today I run the XML-parsing code in the viewDidLoad. Perhaps if I run that code in viewWillAppear instead?
Another question is if I should reload the XML-data each time the user switches back to the tab containing the UITableView with the XML-data. Or s开发者_如何学Pythonhould I in some way which I don't know of check if it's already "fetched"?
Thank you!
My solution was that in the viewDidLoad add this:
loadingIndicator = [[UIActivityIndicatorView alloc] init];
loadingIndicator.frame = CGRectMake(140, 190, 37, 37);
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
[self.view addSubview:loadingIndicator];
[self performSelectorInBackground:@selector(loadIndicator) withObject:loadingIndicator];
[self performSelectorInBackground:@selector(getXmlData) withObject:nil];
This is my current code.
[self getEvents] does the XML-fething and takes like 2 seconds.
loadingIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[self.view addSubview:loadingIndicator];
[loadingIndicator startAnimating];
[self getEvents];
[loadingIndicator stopAnimating];
精彩评论