I created ViewController in Storyboard and I am using
instantiateViewControllerWithIdentifier:
to load it. But I need to have this VC as base class and use 3-4 subclasses to change its properties.
How can I get an instance of my subclass with instantiateViewControllerWithIdentifier
?
Step 1: Set a Storyboard IDIn the Storyboard, select the view controller that you want to instantiate in code. Make sure the yellow circle is highlighted, and click on the Identity Inspector. Set the custom class as well as the field called "Storyboard ID". You can use the class name as the Storyboard ID.
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
@Bhagyesh version in Swift 3:
class func instantiateFromSuperclassStoryboard() -> SubclassViewController {
let stroryboard = UIStoryboard(name: "Main", bundle: nil)
let controller = stroryboard.instantiateViewController(withIdentifier: "BaseViewController")
object_setClass(controller, SubclassViewController.self)
return controller as! SubclassViewController
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With