Unintended table reload/refresh with some delay

后端 未结 2 2039
我寻月下人不归
我寻月下人不归 2021-01-24 23:52

Xcode 6 - beta 6/7: I\'ve created a iOS 8 (Swift) blog reader app with an overview (table view) and a detail view (web view) screen. If there\'s internet connection the app, whe

相关标签:
2条回答
  • 2021-01-25 00:07

    You can also reload UITableView like this

    self.tblMainTable.performSelectorOnMainThread(Selector("reloadData"), withObject: nil, waitUntilDone: true)
    

    As I mentioned here

    0 讨论(0)
  • 2021-01-25 00:19

    I had a similar issue.
    You need to do any ui changes on the main thread. When you do a data request, the callback may not be on the main thread. So to do that do something like this:

    dispatch_async(dispatch_get_main_queue()){    
        self.tableView.reloadData() // reload table/data or whatever here. However you want.
    }
    

    When you load data from a url, you are going to have some sort of callback which will be sent to a closure (a block in objc). When that closure is called it is not guaranteed to be on the main thread. Sometimes it might be and sometimes it will not be. Why running dispatch_async and telling it to grab the main thread with dispatch_get_main_queue() you are saying, run the following code on the main thread. All UI changes must be made from the main thread.

    0 讨论(0)
提交回复
热议问题