我会尽我所能解释我的问题,所以提前谢谢。
我通常通过让每个视图控制器代表不同的视图来构建具有多个视图控制器的应用程序。现在,我正在创建一个具有许多不同视图的大型应用程序。我不希望我的应用程序中有15个以上的ViewController。我宁愿一个ViewController继承不同的UIView。
例如,如果我在菜单栏上选择“配置文件”选项。然后我会被带到selectionController,让selectionController继承名为Settings View的UIView
出于某种原因,在调用函数以显示profileView时,不会发生任何事情。我以前也实现过类似的功能,但它不起作用。
家庭控制器
func displayController(menuOption: MenuOption, view: UIView) {
let selectionController = UIViewController()
selectionController.view.frame = UIScreen.main.bounds
selectionController.navigationItem.title = menuOption.name
selectionController.view.backgroundColor = Color.defaultBackgrondColor
selectionController.view.addSubview(view)
navigationController?.navigationBar.tintColor = UIColor.white
navigationController?.pushViewController(selectionController, animated: true)
}
菜单栏
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
}) { (completed: Bool) in
let option = self.menuOptions[indexPath.row]
switch option.name {
case "Profile":
self.homeController?.displayController(menuOption: option, view: ProfileView(frame: UIScreen.main.bounds))
default:
print("Staying on home page")
}
}
}