I have a UIView
class where I create some buttons and labels programmatically, and I have a view inside a certain ViewController
that is attached to this class. The class works perfectly fine as expected, but whenever I try to link this custom UIView
class to a xib view i get these errors:
-"Main.storyboard: error: IB Designables: Failed to update auto layout status: Interface Builder Cocoa Touch Tool crashed"
-"Rendering the view took longer than 200 ms. Your drawing code may suffer from slow performance.
"
-"error: IB Designables: Failed to render instance of MyView: Rendering the view took longer than 200 ms. Your drawing code may suffer from slow performance.
"
Here is the initialization code in the UIView
class:
@IBDesignable class MyView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
func loadFromNib() -> UIView {
let bundle = NSBundle(forClass: self.dynamicType)
let nib = UINib(nibName: "MyView", bundle: bundle)
let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView
return view
}
func setup() {
var view = loadFromNib()
view.frame = bounds
view.autoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight
addSubview(view)
}
}
Both the class and the xib file have the same name,
UPDATE: I found out that the:
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
Is the one responsible for all the errors, but if I deleted it's content and ran the app the view doesn't show as expected, I also tried awakeFromNib()
and same issues happened.