2

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!

2 Answers 2

10

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];

    });
});
Sign up to request clarification or add additional context in comments.

Comments

3

All your UI operations should be done on the main thread. That's probably the problem.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.