I have two super view controllers MasterCategoryListViewController
and MasterCategoryItemViewController
.
I want to use these in several apps.
I inherit from both of these
class CustomListController: MasterCategoryListViewController
class CustomItemController: MasterCategoryItemViewController
Now in the MasterCategoryListViewController
I have a button handler...
@objc open func btnAddTapped(sender: UIBarButtonItem) {
let itemViewController = MasterCategoryItemViewController()
itemViewController.title = "Type"
self.navigationController?.pushViewController(itemViewController, animated: true)
}
I know I can override the method to push to CustomItemController
however, I'm just wondering if I can do this in my MasterCategoryListViewController
, obviously without it knowing anything about what CustomItemController
?
Create a method on the parent called something like
detailVCClass()
, answering the class that should be instantiated upon button tap. The parent can answer something generic, and the subclasses answer any class that's appropriate for each to know about.Have the button tap method instantiate an instance of
self.detailVCClass()
, rather than a class name literal.