我正在尝试获取一个Twitter帐户列表来加载包含数据的UITableViewController。我用这个函数:
- (void)viewDidLoad {
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
...
[[self tableView] insertRowsAtIndexPaths ...];
[[self tableView] reloadData];
NSLog("This message appears immediately");
...
}];
NSLog("This message appears immediately");
}
由于某种原因,在表实际更新/重绘之前,界面似乎“挂起”了5秒(注意我调用了reloadData!)。我的所有日志消息都会立即打印出来,因此我不确定是什么导致界面冻结。
答案 0 :(得分:16)
所有
所以,我想出来了(有点)。我想它与线程有关,我不应该在那个线程中做任何UI东西。
为了修复它,我用一些调度代码包围了表格:
[account requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error)
{ dispatch_async(dispatch_get_main_queue(), ^{
...
});}];
仍然需要了解这里发生了什么,但希望如果有人遇到同样的问题,这将有所帮助。