Reputation: 1500
In the method viewDidLoad I initialize an ActivityIndicatorView.Then, in the following method I sent the activity indicator to start. When I start the app and it runs the if statement, the activity indicator starts, but when operations in the dispatch queue are performed, the activityIndicator is not stopped. Here the method:
-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if([indexPath row] == [_myArray count]-2){
[_activityIndicator startAnimating];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
//Here I perform some operations
[self.tableView reloadData];
[_activityIndicator stopAnimating];
});
}
}
I wish that the activity indicator is stopped after the execution of operations in the dispatch queue!
Upvotes: 2
Views: 1500
Reputation: 1502
You should perform your UI operations only on main thread. Try to refactor:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
//Here I perform some operations
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
[_activityIndicator stopAnimating];
});
});
Upvotes: 10
Reputation: 9387
All your UI operations should be done on the main thread. That's probably the problem.
Upvotes: 3