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

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

问题描述

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

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:

It needs to be placed inside a different thread that allows the UI to update as soon as execution of thread function completes:

现代斯威夫特:

DispatchQueue.main.async {
    // Update UI
}

Swift 3 之前的旧版本 Swift.

Older versions of Swift, pre Swift 3.

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

目标-C:

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

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

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