在我的应用程序中,我有一个 UITableViewController。
它的 tableView 分为 3 个部分。
我从我的服务器下载每个部分的数据。为此,我有 3 个函数(例如 f1 f2 和 f3)。每个更新一个相应的 NSArray,用作我的表的数据源。
现在我想要的是使用此函数重新加载数据,并在这 3 个函数完成后刷新我的 tableView,但不会打扰用户。
我不使用异步请求、块、线程等......并且我正在寻找提示。
实际上,这就是我所做的:
-(void)viewDidLoad
{
//some settings
[NSTimer scheduledTimerWithTimeInterval:15.0 target:self selector:@selector(reloadDatas) userInfo:nil repeats:YES];
dispatch_queue_t queue = dispatch_get_main_queue();
dispatch_async(queue, ^{
[self reloadDatas];
});
}
-(void)reloadDatas
{
dispatch_queue_t concurrentQueue = dispatch_get_main_queue();
dispatch_async(concurrentQueue, ^{
[self f1];
[self f2];
[self f3];
[myDisplayedTable reloadData];
});
}
-(void)f1
{
//load datas with a url request and update array1
}
-(void)f2
{
//load datas with a url request and update array2
}
-(void)f3
{
//load datas with a url request and update array3
}
但在这里,我的 tableView 被“冻结”,直到刷新。
我不关心f1 f2和f3的执行顺序,但我需要等待这3个函数完成后再刷新我的tableView。
感谢您的帮助。
EDIT
感谢您的所有回答。
这是工作解决方案:
正如 mros 所建议的,我从 viewDidLoad 中删除了调度队列,并替换为 reloadDatas:
dispatch_queue_t concurrentQueue = dispatch_get_main_queue();
with
dispatch_queue_t mainThreadQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
最后,我在主线程中重新加载表
dispatch_async(dispatch_get_main_queue(), ^{ [myDisplayedTable reloadData]; });