When i load a JSON file inside my UITableViewController
it loads and updates my datasource and view, but only renders the update when i touch my screen.
The loading and parsing code i'm using looks like this:
func fetchData() {
let jsonUrl = 'http://myrestserver.com/apicall'
let session = NSURLSession.sharedSession()
let urlObject = NSURL(string: jsonUrl)
let task = session.dataTaskWithURL(urlObject!) {
(data, response, error) -> Void in
do {
let jsonData = try NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers ) as! NSDictionary
var items :[Article] = []
let jsonItems = jsonData["channel"] as! NSArray
for (_, item) in jsonItems.enumerate() {
let article = Article()
article.id = item["id"] as? String
article.title = item["title"] as? String
article.guid = item["guid"] as? String
items.append(article)
}
self.articles.insertContentsOf(items, at: 0)
} catch {
print("error fetchData")
}
}
task.resume()
self.tableView.reloadData()
}
Is there a method i'm not aware of to handle this re-rendering?
I've tried render methods for UITableViewCell
like described here:
setNeedsLayout and setNeedsDisplay
But there is no luck, can someone explain what is the best practice for rendering new records?
Best regards, Jos