UITableView reloadData() 不刷新显示的单元格 [英] UITableView reloadData() does not refresh displayed cells

查看:28
本文介绍了UITableView reloadData() 不刷新显示的单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有

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 StationViewControlleras 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆