UITableView reloadData() does not refresh displaye

2019-04-19 18:06发布

I have

class StationViewController : 
    UITableViewController, UITableViewDelegate, UITableViewDataSource {
  @IBOutlet var stationTableView: UITableView!

When update the data in my data source and do

stationTableView.reloadData()

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())")

which prints the expected cells.

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?

1条回答
女痞
2楼-- · 2019-04-19 19:04

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()
    });
}
查看更多
登录 后发表回答