我已经使用.xib
创建了一个自定义UIView,现在尝试通过init
方法显示它,但我发现了奇怪的Thread 1: Fatal error: init(coder:) has not been implemented
错误。
1.所以,我创建了UIView
xib和swift文件:
override init(frame: CGRect) {
super.init(frame: frame)
createSubview()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func createSubview() {
let newFormView = UINib(nibName: String(describing: NewProfileFormView.self), bundle: nil).instantiate(withOwner: self, options: nil).first as! NewProfileFormView
self.addSubview(newFormView)
}
并将其从另一个ViewController
调用为:
let newProfileViewController = UIViewController()
let newFormView = NewProfileFormView()
newProfileViewController.view = newFormView
self.navigationController?.pushViewController(newProfileViewController, animated: true)
但是上面提到的错误崩溃了。你能帮我找到我的错误吗?