UITableView reloadData() 不刷新显示的单元格 [英] UITableView reloadData() does not refresh displayed cells
问题描述
我有
class StationViewController :
UITableViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var stationTableView: UITableView!
更新我的数据源中的数据时执行
When update the data in my data source and do
stationTableView.reloadData()
这不会立即显示在屏幕上.如果我滚动、倾斜或执行任何其他强制重新绘制屏幕的操作,更新的单元格是可见的.我可以确认UITableView 确实通过调用
this is not immediately visible on the screen. If I scroll, tilt or do anything else which forces a repaint of the screen the updated cells are visible. I can confirm that the UITableView did do the update by calling
println("\(stationTableView.visibleCells())")
打印预期的单元格.
其余的设置是一个 UINavigationController
,它与我的 StationViewController
作为关系.stationViewController
的 IBOutlet 连接到 storyboard 文件中的 UITableView
.
The rest of the setup is a UINavigationController
which has my StationViewController
as a relationship. The IBOutlet for the stationViewController
is connected to the UITableView
in the storyboard file.
我似乎需要对屏幕进行重绘"才能使我的更新立即可见.我该怎么做?
I seem to need a "repaint" of the screen to make my update immediately visible. How do I do that?
推荐答案
感谢 Artem,我发现我需要在主线程上调用 reloadData().我是这样解决的:
Thanks to Artem, I figured out I need to call reloadData() on the main thread. This is how I solved that:
func refreshUI() {
dispatch_async(dispatch_get_main_queue(),{
self.stationTableView.reloadData()
});
}
这篇关于UITableView reloadData() 不刷新显示的单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!