繁体   English   中英

活动指标不会以相同的方法停止

[英]Activity Indicator doesn't stop in the same method

在方法viewDidLoad中我初始化了一个ActivityIndi​​catorView。然后,在下面的方法中,我发送了活动指示符来启动。 当我启动应用程序并运行if语句时,活动指示器会启动,但是当执行调度队列中的操作时,activityIndi​​cator不会停止。 这里的方法:

-(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];
        });
    }
}

我希望在调度队列中执行操作后停止活动指示器!

您应该只在主线程上执行UI操作。 尝试重构:

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

    });
});

您的所有UI操作都应该在主线程上完成。 那可能就是问题所在。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM