I have a ViewController (BViewController
) that's inheriting from another UIViewController
Subclass (AViewController
). (The reason I want to do this is I'm reusing the same view in storyboard 3+ times for different screens.)
When I call:
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "AViewController") as! BViewController
self.show(vc, sender: self)
I get this error:
Could not cast value of type 'test.AViewController' (0x10d08b478) to 'test.BViewController' (0x10d08b3f0).
Here are my subclasses, they have nothing in them.
class AViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
-
class BViewController: AViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
The class in Storyboard is set to AViewController
because I'm trying to share IBOutlets
across all children without recreating the views. There is only one View Controller Scene
in my UIStoryboard
.