I have created a custom UIView with .xib
and now trying to display it through init
method but I get strange Thread 1: Fatal error: init(coder:) has not been implemented
error.
1. So, I have created UIView
xib and swift file:
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)
}
and call it from another ViewController
as:
let newProfileViewController = UIViewController()
let newFormView = NewProfileFormView()
newProfileViewController.view = newFormView
self.navigationController?.pushViewController(newProfileViewController, animated: true)
but it crashes with above mentioned error. Could you please help me to find my mistake?