The code you've presented puzzles me a bit. I think what you should do is present the activity indicator in the parserDidStartDocument
method and remove it in parserDidEndDocument
. I suggest creating another UIView
property, name it activityIndicatorView
, and do something like this:
- (void)parserDidStartDocument:(NSXMLParser *)parser {
if (!self.activityIndicatorView) {
self.activityIndicatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 60)];
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:(UIActivityIndicatorViewStyleGray)];
self.activityIndicator.center = CGPointMake(self.activityIndicatorView.frame.size.width/2,self.activityIndicatorView.frame.size.height/2);
[self.activityIndicatorView addSubview:self.activityIndicator];
}
self.tableView.tableHeaderView = self.activityIndicatorView;
[self.activityIndicator startAnimating];
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
[self.tableView reloadData];
[self.activityIndicator stopAnimating];
self.tableView.tableHeaderView = nil;
}
I don't know what your project looks like, but I assume you're doing something with the parsed document before reloading the table.