enter code here
Firstable why you if
everything? In every if you have the same set of method call.
Then you have leave reusability if in the beginning of your method:
if(cell.accessoryView==nil)
I assume that is a mistake.
And finally you fire the animation on some other thread, you cannot do that - always call main thread for animation:
So your method should look like:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[parseArray removeAllObjects];
[self.view addSubview:activityIndicator];
// [NSThread detachNewThreadSelector:@selector(threadStartAnimating:) toTarget:self withObject:nil]; // this line have to be rewrite. I write solution below.
[self xmlParsing];
[activityIndicator stopAnimating];
}
}
Now let's focus on thread-safety animation. Call your method "normally" like [self threadStartAnimating:self];
in above method. Then modify it like:
-(IBAction) threadStartAnimating:(id)object {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//do all your task here (task, witch not included pushing or taking something from/to the screen).
dispatch_async(dispatch_get_main_queue(), ^{
//here is the place to redraw the screen like [self.view addSubview:mySub];
});
});
}