我正在重构我的代码,并想尝试一下协调员。
但是,我UINavigationController
不太愿意负责,因为它会在子坐标上创建一个后退按钮以及一个我不想要的不需要的顶部栏。
反正我可以用普通UIViewController
代替UINavigationController
吗?
PS:这是我找到的示例代码 [这里][1]
协议协调器 { func start() }
协议 FlowACoordinatable { var coordinator: FlowACoordinator }
类FlowACoordinator:协调器{
private var navigationController: UINavigationController
private var firstVC: FirstViewController
private var secondVC: SecondViewController
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}
func start() { ... }
func present(_ viewController: (FlowACoordinatable & UIViewController)) {
viewController.coordinator = self
self.navigationController.pushViewController(viewController, animated: true)
}
...
}
类 FirstViewController: UIViewController, FlowACoordinatable {
var coordinator: FlowACoordinator?
func buttonTapped() {
self.coordinator?.goToNextStep()
}
}