我有一個UIView
類,其中我通過編程創建了一些按鈕和標籤,並且在附加到此類的某個ViewController
中有一個視圖。類按預期工作完全正常,但每當我嘗試這個自定義UIView
類鏈接到廈門國際銀行查看我得到這些錯誤:Xcode - 將xib文件附加到自定義UIView類時出錯
-"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.
"
這裏是在UIView
類的初始化代碼:
@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)
}
}
無論是類和廈門國際銀行文件具有相同的名稱,
更新:我發現了:
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setup()
}
是一個負責所有的錯誤,但如果我刪除它的內容和運行該應用程序視圖不會如預期顯示,我也試過awakeFromNib()
併發生同樣的問題。
請檢查OP中的更新。 – Abdou023