问题描述
我有一个 UITableview,我加载了异步数据,因此 tableview 可能会在没有数据的情况下出现.
我已经厌倦了 ReloadData 方法,但在我滚动 tableview 之前,tableview 一直是空的,突然出现数据.
当我将 tableview 作为详细视图加载并在项目之间切换时,会发生同样的事情,前一个项目数据首先出现,一旦我在 table view 中滚动它就会显示正确的数据.
我的猜测是 ReloadData 方法工作得很好,但我需要以某种方式重绘 tableview,关于如何解决这个问题的任何建议?
I have a UITableview that I load with data async so the tableview might appear without data.
I have tired the ReloadData method but the tableview remains empty until I scroll the tableview, suddenly the data appears.
The same thing happens when I load a tableview as a detailedview and switching between items, the previoud items data appears first and as soon as I scroll in the table view it shows the correct data.
My guess is that the ReloadData method works just fine, but I need to redraw the tableview somehow, any suggestions on how to solve this?
/吉米
推荐答案
您说您正在异步填充内容,但您是否在主线程的上下文中调用了 reloadData ?(而不是通过填充内容的线程)
You said you're populating content asynchronously but did you invoke the reloadData in the context of the main thread ? (and not via the thread that populates the content)
目标 C
[yourUITableView performSelectorOnMainThread:@selector(reloadData)
withObject:nil
waitUntilDone:NO];
迅捷
dispatch_async(dispatch_get_main_queue(), { self.tableView.reloadData() })
单点触控
InvokeOnMainThread(() => this.TableView.ReloadData());
这篇关于异步更新数据后重绘 UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!