将自定义UIView作为nib加载显示错误EXC_BAD_ACCESS

时间:2016-06-20 06:55:22

标签: ios swift nib

我正在尝试从笔尖加载Custom UIView,但它在

上显示错误

super.init(coder: aDecoder) EXC_BAD_ACCESS

required init?(coder aDecoder: NSCoder) {
    // call super.init(coder:)
    super.init(coder: aDecoder)

    // Setup view from .xib file
    self.xibSetup()
}

当我尝试打印aDecoder时,它会打印为

  

error: Trying to put the stack in unreadable memory at: 0x7fff5ba3af00.

我的func xibSetup()如下:

fun xibSetup() {
let bundle = NSBundle(forClass: self.dynamicType)
    let nib = UINib(nibName: "Dialog", bundle: bundle)

    // Assumes UIView is top level and only object in CustomView.xib file
    let view = nib.instantiateWithOwner(self, options: nil)[0] as! UIView

// use bounds not frame or it'll be offset
    view.frame = bounds

    // Make the view stretch with containing view
    view.autoresizingMask = [UIViewAutoresizing.FlexibleWidth, UIViewAutoresizing.FlexibleHeight]

    // Adding custom subview on top of our view (over any custom drawing > see note below)
    addSubview(view) }

0 个答案:

没有答案