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
You can also reload UITableView like this
self.tblMainTable.performSelectorOnMainThread(Selector("reloadData"), withObject: nil, waitUntilDone: true)
As I mentioned here
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.