Reputation: 43
I am building a single viewcontroller app using UITableViewController in Swift 2.
The problem I am having here is if I load data inside viewDidLoad function, the UITableView displays well with the data.
However, I am trying to have get this data from a custom delegate method, which is called after the data is saved into core data, then self.tableview.reloadData() the UITableView won't display the data.
From my debugging, looks like the
override func numberOfSectionsInTableView(tableView: UITableView) -> Int
and
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
run before my custom delegate method
func didReceiveQualifications(qualifications: [Qualification]) {
print("didReceivedQualifications")
self.qualifications = qualifications
// Pass qualification to view
self.tableView.reloadData()
}
Upvotes: 4
Views: 625
Reputation: 35392
It can be depend by where didReceiveQualifications()
has launched..in which thread running..
All updates to the UI should be done in the main thread.
Try to make reloadData to the main thread:
func didReceiveQualifications(qualifications: [Qualification]) {
print("didReceivedQualifications")
self.qualifications = qualifications
// Pass qualification to view
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
Upvotes: 1