I have a BaseViewController connected to it's .xib and want to subclass it with SubViewController in my storyboard to add more views. I already have do similar setup with UIView but it doesn't work for UIViewcontroller. With no particular code, i only see SubViewController "screen" designed from storyboard. The BaseViewController xib is not loaded.
If i put below code in BaseViewController then i can see all the views from it but not from BaseViewController
public required init?(coder: NSCoder) {
super.init(coder: coder)
let bundle = Bundle(for: type(of: self))
var myCustomView = UINib(nibName: "BaseViewController", bundle: bundle).instantiate(withOwner: self, options: nil)[0] as? BaseViewController
}
With this code in BaseViewController i get "Can't add self as subview":
let bundle = Bundle(for: type(of: self))
guard let view = bundle.loadNibNamed("BaseViewController", owner: self, options: nil)?.first as? UIView else {
return
}
self.view.addSubview(view)
view.frame = self.view.bounds
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
For the moment i can only have either BaseViewController or SubViewController views on screen but not both. The goal is to have BaseViewController xib setup behind the SubViewController views.
Can this be done with UIViewcontroller or does i do it the wrong way ?
After a lot of testing, it's just not possible to sublcass a UIViewcontroller and keep both the base code and add the new subclassed code to it.