iOS - another thread needs to send reloadData to the mainthread

廉价感情. 提交于 2019-11-28 11:23:25
[self.tableView performSelectorOnMainThread:@selector(reloadData)
                                 withObject:nil
                              waitUntilDone:NO];

You can use dispatch async, this method allows you to marshal worker thread to blocks of in-line code rather than methods using performSelectorOnMainThread:

dispatch_async(dispatch_get_main_queue(), ^{
    [self.tableview reloadData];
});'

How about something like this? (may not compile, I am typing it out)

- (void) callReloadData
{
    if ([NSThread isMainThread]) {
        @synchronized (self.tableView) {
            [self.tableView reloadData];
        }
    } else {
        [self performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!