“该应用程序正在从后台线程修改自动布局引擎”。 [英] "This application is modifying the autolayout engine from a background thread"
问题描述
我遇到以下错误:
此应用程序正在从后台线程修改autolayout引擎,这会导致引擎损坏每当我尝试将图像视图加载到表格视图中时,我就会发生奇怪的崩溃
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()
}
每次我点击表格中的图像时图像移动到单元格的左侧,如果我加载的图像不是UIImageView的大小,那么它会调整大小。
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.
如何修复此错误?
我已经尝试过dispatch_get_main_queue代码,但它对我来说似乎没什么用。
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:
+[NSException raise:format:]
您可以这样做:
然后:
之后,一旦你的应用程序卡在断点上,请抓住并共享堆栈跟踪。您可以使用lldb控制台执行此操作:
After that once your app get stuck on the breakpoint, please grab and share the stack trace. You can do this using lldb console:
(lldb) bt
* thread #4: tid = 0x2bbc48, 0x000000010ba5ebf0 CoreFoundation`+[NSException raise:format:], queue = 'com.apple.root.default-qos', stop reason = breakpoint 1.1
* frame #0: 0x000000010ba5ebf0 CoreFoundation`+[NSException raise:format:]
frame #1: 0x0000000108dd5b6b Foundation`_AssertAutolayoutOnMainThreadOnly + 79
frame #2: 0x0000000108dd5a62 Foundation`-[NSISEngine _optimizeWithoutRebuilding] + 49
frame #3: 0x0000000108c34c0f Foundation`-[NSISEngine optimize] + 46
frame #4: 0x0000000108c3b875 Foundation`-[NSISEngine constraintDidChangeSuchThatMarker:shouldBeReplacedByMarkerPlusDelta:] + 313
frame #5: 0x0000000108c3b6f2 Foundation`-[NSISEngine tryToChangeConstraintSuchThatMarker:isReplacedByMarkerPlusDelta:undoHandler:] + 440
frame #6: 0x0000000108c27715 Foundation`-[NSLayoutConstraint _tryToChangeContainerGeometryWithUndoHandler:] + 484
frame #7: 0x0000000108c27274 Foundation`-[NSLayoutConstraint _setSymbolicConstant:constant:] + 422
frame #8: 0x0000000108ac35d5 iosapp`ViewController.(self=0x00007fe86a6abc80) -> ()).(closure #1) + 133 at ViewController.swift:26
frame #9: 0x0000000108ac3627 iosapp`thunk + 39 at ViewController.swift:0
frame #10: 0x000000010c775d9d libdispatch.dylib`_dispatch_call_block_and_release + 12
frame #11: 0x000000010c7963eb libdispatch.dylib`_dispatch_client_callout + 8
frame #12: 0x000000010c77eb2f libdispatch.dylib`_dispatch_root_queue_drain + 1829
frame #13: 0x000000010c77e405 libdispatch.dylib`_dispatch_worker_thread3 + 111
frame #14: 0x000000010cad34de libsystem_pthread.dylib`_pthread_wqthread + 1129
frame #15: 0x000000010cad1341 libsystem_pthread.dylib`start_wqthread + 13
(lldb)
完成此操作后,我们可以确定导致问题的确切位置。
Once you've done this, we can identify exact place which causes the issue.
这篇关于“该应用程序正在从后台线程修改自动布局引擎”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!