在我的OS X中使用swift遇到了很多这个错误:
“这个应用程序正在从后台线程修改自动布局引擎,这可能会导致引擎损坏和奇怪的崩溃。这将在未来的版本中导致异常。”
我有一个NSWindow我将视图交换到窗口的contentView。当我尝试执行NSApp时会得到错误。或者当我向窗口添加子视图时。尝试禁用自动调整大小的东西,我没有任何使用自动布局的东西。任何想法吗?
有时它很好,什么都没有发生,其他时候它完全破坏了我的UI,什么都没有加载
在我的OS X中使用swift遇到了很多这个错误:
“这个应用程序正在从后台线程修改自动布局引擎,这可能会导致引擎损坏和奇怪的崩溃。这将在未来的版本中导致异常。”
我有一个NSWindow我将视图交换到窗口的contentView。当我尝试执行NSApp时会得到错误。或者当我向窗口添加子视图时。尝试禁用自动调整大小的东西,我没有任何使用自动布局的东西。任何想法吗?
有时它很好,什么都没有发生,其他时候它完全破坏了我的UI,什么都没有加载
当前回答
“此应用程序正在从后台线程修改自动布局引擎”错误在实际问题发生后很长时间才会记录在控制台中,因此如果不使用断点,调试这个错误可能会很困难。
我使用@markussvensson的答案来检测我的问题,并使用这个符号断点(调试>断点>创建符号断点)发现它:
符号:[UIView layoutIfNeeded]或[UIView updateConstraintsIfNeeded] 条件:!(BOOL)[NSThread是主线程]
在模拟器上构建和运行应用程序,并复制导致抛出错误消息的步骤(应用程序将比平时慢!)然后Xcode将停止应用程序并标记从后台线程访问UI的代码行(例如func的调用)。
其他回答
对我来说,问题是这样的。 确保在主线程上执行performSegueWithIdentifier::
dispatch_async (dispatch_get_main_queue(), ^{
[self performSegueWithIdentifier:@"ViewController" sender:nil];
});
当我在一个NSURLConnection异步请求完成处理程序中调用一个做UI更新的块时,我有这个问题,因为更新到iOS 9 SDK。使用dispatch_main_queue将块调用放在dispatch_async中解决了这个问题。
它在iOS 8中运行良好。
我有同样的问题时,试图更新错误消息在UILabel在同一个ViewController(它需要一点时间来更新数据时,试图这样做的正常编码)。我在Swift 3 Xcode 8中使用了DispatchQueue,它可以工作。
我在UITableView中重新加载数据时遇到了这个问题。简单调度重新加载如下固定的问题为我。
dispatch_async(dispatch_get_main_queue(), { () -> Void in
self.tableView.reloadData()
})
I also encountered this problem, seeing a ton of these messages and stack traces being printed in the output, when I resized the window to a smaller size than its initial value. Spending a long time figuring out the problem, I thought I'd share the rather simple solution. I had once enabled Can Draw Concurrently on an NSTextView through IB. That tells AppKit that it can call the view's draw(_:) method from another thread. After disabling it, I no longer got any error messages. I didn't experience any problems before updating to macOS 10.14 Beta, but at the same time, I also started modifying the code to perform work with the text view.