I am having an error of:
This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes
whenever I try to load an image view into a table view. The relevant code is as follows:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cellIdentifier = "ArticleCell"
let cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier, forIndexPath: indexPath) as! ArticleCell
let a: Article = self.articlesArray[indexPath.row] as! Article
//let a: Article = self.newArticlesArray[indexPath.row] as! Article
cell.titleLabel.text = a.title
cell.descLabel.text = a.desc
let data = NSData(contentsOfURL: a.thumbnail)
cell.iView.image = UIImage(data: data!)
return cell
}
func downloadArticles(){
//JSON parsing methods here
self.syncCompleted = true
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
}
}
task.resume()
}
Every time I click the image in my table view the image moves to the left of the cell and if the image I loaded is not the size of the UIImageView then it resizes it all.
How would I fix this error?
I have tried the dispatch_get_main_queue code, but it does not seem to be doing much for me.
Let's identify exact execution path which leads to auto layout engine corruption. For this you need to add symbolic breakpoint to following:
You can do this following way:
Then:
After that once your app get stuck on the breakpoint, please grab and share the stack trace. You can do this using lldb console:
Once you've done this, we can identify exact place which causes the issue.