获得“此应用程序正在从后台线程修改自动布局引擎".错误? [英] Getting a "This application is modifying the autolayout engine from a background thread" error?

查看:78
本文介绍了获得“此应用程序正在从后台线程修改自动布局引擎".错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用swift在我的OS X中经常遇到此错误:

Been encountering this error a lot in my OS X using swift:

此应用程序正在从后台线程修改自动布局引擎,这可能导致引擎损坏和怪异的崩溃.这将在以后的版本中引发异常."

"This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes. This will cause an exception in a future release."

我有一个 NSWindow ,并且正在将视图交换到窗口的contentView.尝试在窗口上执行NSApp.beginSheet时,或在窗口中添加subview时,都会出现错误.试图禁用自动调整大小的东西,并且我没有使用自动布局的东西.有什么想法吗?

I have a my NSWindow and I'm swapping in views to the contentView of the window. I get the error when I try and do a NSApp.beginSheet on the window, or when I add a subview to the window. Tried disabling autoresize stuff, and I don't have anything using auto layout. Any thoughts?

有时候没事,什么也没发生,有时它完全破坏了我的UI并且没有负载

Sometimes it's fine and nothing happens, other times it totally breaks my UI and nothing loads

推荐答案

好的-找到了答案.需要将其放置在不同的线程中,该线程允许UI在执行完线程功能后立即进行更新:

Okay - found the answer. It needs to be placed inside a different thread that allows the UI to update as soon as execution of thread function complete :

 DispatchQueue.main.async {
    // Update UI
 }

迅速版本< 3

dispatch_async(dispatch_get_main_queue(){
    // code here
})

Objective-C版本

dispatch_async(dispatch_get_main_queue(), ^{
    // code here
});

这篇关于获得“此应用程序正在从后台线程修改自动布局引擎".错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆