UITableView reloadData taking too much time

佐手、 提交于 2019-12-04 15:23:26

I know this is a really old question, but I've just come across the exact same issue and think I might know the cause. Might help someone who stumbles across this same question...

I suspect that your reloadData call is happening on a background thread as opposed to the main thread. What you describe is the exact effect of this - the code runs but there is a long delay (5-10 secs) in updating the user interface.

Try changing the reloadData call to:

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

You are calling reloadData on a thread other than the mainThread

Make sure to reload your tableView's data on main thread like in the below:

OBJ-C:

[self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

Swift 3:

DispatchQueue.main.async {
   self.tableView.reloadData()
}

Where does:

- (void)createRequestFromXMLElement:(TBXMLElement *)element

get called? Sound like you might be making 20 web requests to get that file contents. That would definitely make things slow (as opposed to doing one request to get the entire XML file and parsing that locally).

Can you post your whole VC code?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!