I am going to do my best to explain my problem, so thanks in advance.
I usually build applications with many view controllers by having each ViewController represent a different view. Right now, I am creating a large application with many different views. I do not want to have 15 plus View Controllers in my application. I would rather have one ViewController inherit different UIViews.
For example, if on my menu bar I select the "Settings" option. I would then be taken to the selectionController and have the selectionController inherit the UIView named Settings View
At the moment I am able to navigate to my settingsController and have the Navbar represent the option selected. But how would I go about inheriting the View as well?
When an option is selected this function is called..
//Whatever option selected will affect which view is inherited
let option = self.menuOptions[indexPath.row]
if option.name != "Home" {
self.homeController?.displayController(menuOption: menuOption, view: self.settingsView)
}
Home Controller
class HomeController: UIViewController {
lazy var menu: Menu = {
let menuLauncher = Menu()
menuLauncher.homeController = self
return menuLauncher
}()
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Home"
view.backgroundColor = Color.blue
navigationItem.leftBarButtonItem = UIBarButtonItem(image: UIImage(named: "menu"), style: .plain, target: self, action: #selector(displayMenu))
}
func displayController(menuOption: MenuOption, view: UIView) {
let selectionController = UIViewController()
selectionController.navigationItem.title = menuOption.name
selectionController.view.backgroundColor = Color.blue
//Why dosen't this present the view I have assigned to it??
selectionController.view.addSubview(HomeView(frame: view.frame))
navigationController?.navigationBar.tintColor = UIColor.white
navigationController?.pushViewController(selectionController, animated: true)
}
@objc func displayMenu() {
menu.displayMenu()
}
}