ios @IBDesignable 错误:IB Designables:无法更新自动布局状态:Interface Builder Cocoa Touch Tool 崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27374330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
@IBDesignable error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed
提问by Albert Bori
I have a very simple subclass of UITextView that adds the "Placeholder" functionality that you can find native to the Text Field object. Here is my code for the subclass:
我有一个非常简单的 UITextView 子类,它添加了“占位符”功能,您可以在 Text Field 对象中找到该功能。这是我的子类代码:
import UIKit
import Foundation
@IBDesignable class PlaceholderTextView: UITextView, UITextViewDelegate
{
@IBInspectable var placeholder: String = "" {
didSet {
setPlaceholderText()
}
}
private let placeholderColor: UIColor = UIColor.lightGrayColor()
private var textColorCache: UIColor!
override init(frame: CGRect) {
super.init(frame: frame)
self.delegate = self
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.delegate = self
}
func textViewDidBeginEditing(textView: UITextView) {
if textView.text == placeholder {
textView.text = ""
textView.textColor = textColorCache
}
}
func textViewDidEndEditing(textView: UITextView) {
if textView.text == "" && placeholder != "" {
setPlaceholderText()
}
}
func setPlaceholderText() {
if placeholder != "" {
if textColorCache == nil { textColorCache = self.textColor }
self.textColor = placeholderColor
self.text = placeholder
}
}
}
After changing the class for the UITextView
object in the Identity Inspector to PlaceholderTextView
, I can set the Placeholder
property just fine in the Attribute Inspector. The code works great when running the app, but does not display the placeholder text in the interface builder. I also get the following non-blocking errors (I assume this is why it's not rendering at design time):
UITextView
将 Identity Inspector 中对象的类更改为 后PlaceholderTextView
,我可以Placeholder
在 Attribute Inspector 中很好地设置该属性。该代码在运行应用程序时效果很好,但不会在界面构建器中显示占位符文本。我还收到以下非阻塞错误(我认为这就是它不在设计时呈现的原因):
error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed
error: IB Designables: Failed to render instance of PlaceholderTextView: Rendering the view took longer than 200 ms. Your drawing code may suffer from slow performance.
错误:IB Designables:无法更新自动布局状态:Interface Builder Cocoa Touch Tool 崩溃
错误:IB Designables:无法呈现 PlaceholderTextView 的实例:呈现视图的时间超过 200 毫秒。您的绘图代码可能会受到性能缓慢的影响。
I'm not able to figure out what is causing these errors. The second error doesn't make any sense, as I'm not even overriding drawRect(). Any ideas?
我无法弄清楚是什么导致了这些错误。第二个错误没有任何意义,因为我什至没有覆盖 drawRect()。有任何想法吗?
回答by Petter
There are crash reports generated when Interface Builder Cocoa Touch Tool crashes. Theses are located in ~/Library/Logs/DiagnosticReports
and named IBDesignablesAgentCocoaTouch_*.crash
. In my case they contained a useful stack-trace that identified the issue in my code.
Interface Builder Cocoa Touch Tool 崩溃时会生成崩溃报告。论文位于~/Library/Logs/DiagnosticReports
并命名IBDesignablesAgentCocoaTouch_*.crash
。就我而言,它们包含一个有用的堆栈跟踪,可以识别我的代码中的问题。
回答by Dustin Williams
I have had the same issue a couple of times. Both times it started when I was loading an IBDesignable nib onto the storyboard when the nib was not able to fit on the view (ie I had a button off of the UIView but still in the nib). Once I fixed that Xcode still gave me errors so I restarted Xcode until it randomly stopped giving me the error.
我遇到过同样的问题几次。两次它都是在我将 IBDesignable 笔尖加载到情节提要上时开始的,而笔尖无法适应视图(即,我在 UIView 上有一个按钮,但仍在笔尖中)。一旦我修复了 Xcode 仍然给我错误,所以我重新启动 Xcode,直到它随机停止给我错误。
I hope this helps.
我希望这有帮助。
UPDATE: I just killed all processes named "Interface Builder Cocoa Touch Tool", restarted Xcode and the error went away. Don't know if this will always work or not.
更新:我刚刚杀死了所有名为“Interface Builder Cocoa Touch Tool”的进程,重新启动了 Xcode,错误就消失了。不知道这是否总是有效。
回答by jmoukel
In my case, I was doing the next in the initWithFrame/initWithCoder methods to create the view:
就我而言,我在 initWithFrame/initWithCoder 方法中执行下一个操作来创建视图:
className = NSStringFromClass([self class]);
self.view = [[[NSBundle mainBundle] loadNibNamed:className owner:self options:nil] firstObject];
It looks like I was Notsupposed to use the Main Bundle, but instead the bundle of the class. So I replaced that code for the following and it worked:
看起来我不应该使用Main Bundle,而是使用类的包。所以我替换了以下代码并且它起作用了:
bundle = [NSBundle bundleForClass:[self class]];
className = NSStringFromClass([self class]);
self.view = [[bundle loadNibNamed:className owner:self options:nil] firstObject];
I thought maybe this might help somebody.
我想也许这可能会帮助某人。
回答by Fyodor Volchyok
You could select your custom view in Interface Builder and then use
Editor
, Debug Selected Views
. It will launch so-called IBDesignableAgentCocoaTouch
debug session when all breakpoints (including exception breakpoints) work and you could exactly identify the place your view crashes.
您可以在 Interface Builder 中选择您的自定义视图,然后使用
Editor
, Debug Selected Views
。IBDesignableAgentCocoaTouch
当所有断点(包括异常断点)工作时,它将启动所谓的调试会话,您可以准确地识别视图崩溃的位置。
回答by Zaid Pathan
For Xcode 8 - Swift
对于Xcode 8 - Swift
Adding optional value as default value on @IBInspectable
causing issue for me.
添加可选值作为默认值@IBInspectable
导致我出现问题。
This won't work:
这行不通:
@IBInspectable var repeatImage: UIImage = UIImage(named:"myImage")!{
didSet {
// configureView
}
}
This should work:
这应该有效:
@IBInspectable var repeatImage: UIImage = RepeatImageView.getDefaultImage() {
didSet {
// configureView()
}
}
class func getDefaultImage() -> UIImage {
if let defaultImage = UIImage(named: "myImage") {
return defaultImage
} else {
return UIImage()
}
}
回答by Nick Cross
I was experiencing the similar Interface Builder issues rendering designables.
我在渲染可设计对象时遇到了类似的 Interface Builder 问题。
Using the technique suggested in this answerI was able to track down the issue to the use of image literals.
使用此答案中建议的技术,我能够将问题追溯到图像文字的使用。
Rendering crash
渲染崩溃
self.backgroundImage.image = #imageLiteral(resourceName: "rectangleCenter")
No rendering crash
没有渲染崩溃
self.backgroundImage.image = UIImage(named: "rectangleCenter")
回答by Yusuf Kamil AK
Actually if you have some olduser defined attributes(which is not valid for current view) at any view in your storyboard, that may cause your agent to crash.
实际上,如果您在故事板中的任何视图中有一些旧的用户定义属性(对当前视图无效),则可能会导致您的代理崩溃。
Besides, sometimes it happens just because of a nasty bug of Xcode. To check it out, when you're at storyboard uncheck Editor > Automatically Refresh Views, then move to another file, clean and restart your project. After you entered storyboard again, you can click Editor > Refresh Views and check automatic one again. That one also solved my problem once.
此外,有时它只是因为 Xcode 的一个讨厌的错误而发生。要检查它,当您在故事板时取消选中 Editor > Automatically Refresh Views,然后移动到另一个文件,清理并重新启动您的项目。再次进入故事板后,您可以单击编辑器>刷新视图并再次选中自动。那一个也解决了我的问题一次。
If both didn't work, then probably you have done something wrong about your IBDesignable view, so choose your crashed views in storyboard and debug by clicking Editor > Debug Views
如果两者都不起作用,那么您可能对 IBDesignable 视图做错了,因此在故事板中选择崩溃的视图并通过单击编辑器 > 调试视图进行调试
回答by tzaloga
This is not the case for this question, but maybe I will help someone else.
对于这个问题,情况并非如此,但也许我会帮助其他人。
I had a similar problem when in my @IBDesignable class I did not implemented both:
在我的 @IBDesignable 类中我没有实现这两个时,我遇到了类似的问题:
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
// custom setup
}
override init(frame: CGRect) {
super.init(frame: frame)
// custom setup
}
回答by Jimmy Ng
I had the same issue and I solved it by adding the 'use_frameworks!' to my project's Podfile.
我遇到了同样的问题,我通过添加“use_frameworks!”解决了这个问题。到我的项目的 Podfile。
Hope it helps you.
希望对你有帮助。
回答by AkademiksQc
In my case it was somehow related to a carthage framework that I was using. I had to add $(PROJECT_DIR)/Carthage/Build/iOS to the Runpath Search Pathsbuild setting
就我而言,它与我使用的迦太基框架有某种关系。我必须将 $(PROJECT_DIR)/Carthage/Build/iOS 添加到Runpath Search Paths构建设置