【问题标题】:Do I have to use NavigationController in my coordinators code?我必须在我的协调器代码中使用 NavigationController 吗?
【发布时间】:2023-03-10 01:08:01
【问题描述】:

我正在重构我的代码,想试试协调员。

但是,我不太喜欢 UINavigationController 负责,因为它会在子坐标上创建一个返回按钮以及一个我不想要的不需要的顶部栏。

有没有我可以使用普通的UIViewController 而不是UINavigationController

P.S : 这是我在 [Here][1] 找到的示例代码

协议协调器{ 函数开始() }

协议 FlowACoordinatable { var 协调器: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()
}

}

【问题讨论】:

    标签: swift4 coordinator-pattern transition-coordinator


    【解决方案1】:

    回答我自己的问题...

    协调器架构基于UINavigationController不能替换为UIViewController

    但是,仍然可以使用 Object Inspection 隐藏按钮栏窗格并选中 Hide button bar... 或者这样做by code

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      • 2015-08-26
      • 2011-08-30
      • 2012-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多