![](/img/trans.png)
[英]webView didFinish Navigation is not Working and activity indicator doesn't stop
[英]Activity Indicator doesn't stop in the same method
在方法viewDidLoad中我初始化了一个ActivityIndicatorView。然后,在下面的方法中,我发送了活动指示符来启动。 当我启动应用程序并运行if语句时,活动指示器会启动,但是当执行调度队列中的操作时,activityIndicator不会停止。 这里的方法:
-(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.