我下载了毒蛇模块的模板,但它在视图上没有链接,我如何在这里使用导航?
场景代理
let startModule = CardsCollectionRouter.createModule()
let navigationController = UINavigationController(rootViewController: startModule)
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
路由器
class CardsCollectionRouter: PresenterToRouterCardsCollectionProtocol {
// MARK: Static methods
static func createModule() -> UIViewController {
let viewController = CardsCollectionViewController()
let presenter: ViewToPresenterCardsCollectionProtocol & InteractorToPresenterCardsCollectionProtocol = CardsCollectionPresenter()
let networkService = NetworkService()
viewController.presenter = presenter
viewController.presenter?.router = CardsCollectionRouter()
viewController.presenter?.view = viewController
viewController.presenter?.interactor = CardsCollectionInteractor(networkService: networkService)
viewController.presenter?.interactor?.presenter = presenter
return viewController
}
func showDescription(description: CharacterModel?) {
let descriptionVC = DescripModuleRouter.createModule(description: description)
//How to go on next screen??
let viewController = CardsCollectionViewController()
viewController.navigationController?.pushViewController(descriptionVC, animated: true)
}
}
也许我有一种简单的方法可以获得到该视图的链接?
就像路由器上的view.goToAnotherScreen,我将在我的视图控制器上使用此方法
1条答案
按热度按时间sdnqo3pr1#
在使用此模式时,您不应该在路由器外部创建导航方法,因为导航是路由器的责任。您可以创建
router.goToAnotherScreen
并从您的视图控制器调用它。在创建路由器时,您应该将视图控制器传递给路由器,并且在您的路由器内部应该调用viewController.navigationController?.push...