【发布时间】:2021-04-05 10:29:08
【问题描述】:
我有一个外部XIB,即@IBDesignable。
在显示这个XIB 的视图中,我有这个出口。
@IBOutlet weak var digitizingButton: DigitizingButton! {
didSet {
digitizingButton.buttonIsBeingTouched = {[weak self] in
// bla bla
}
}
}
崩溃
digitizingButton.buttonIsBeingTouched = {[weak self] in
EXC_BAD_ACCESS(代码 2)
DigitizingButton 加载如下:
required init?(coder decoder: NSCoder) {
super.init(coder: decoder)
self.loadViewFromNib()
}
override init(frame: CGRect) {
super.init(frame: frame)
self.loadViewFromNib()
}
/** Loads instance from nib with the same name. */
func loadViewFromNib() {
let bundle = Bundle(for: type(of: self))
let nib = UINib(nibName: .init(String(describing: type(of: self))), bundle: bundle)
let myView = nib.instantiate(withOwner: self, options: nil)[0] as! UIView
self.view = myView
self.addSubview(myView)
}
有什么想法吗?提前致谢。
【问题讨论】:
标签: swift swift5 ibdesignable