我一直在遵循Paul哈德逊关于coordinator模式的教程,遇到了一个必须使用选项卡栏控制器的示例。在显示选项卡栏控制器后,即使我有导航控制器示例,我也无法从一个地方移动到另一个地方。
我有一个主协调员来启动申请流程:
class MainCoordinator: Coordinator {
var childCoordinators = [Coordinator]()
var navigationController: UINavigationController
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}
func start() {
let vc = ViewController.instantiate(storyboard: .main)
vc.coordinator = self
navigationController.pushViewController(vc, animated: false)
}
func navigateToCreateAccount(){
let vc = CreateAccountVC.instantiate(storyboard: .main)
vc.coordinator = self
navigationController.pushViewController(vc, animated: true)
}
func navigateToBuySubscription(){
let vc = BuySubscriptionVC.instantiate(storyboard: .main)
vc.coordinator = self
navigationController.pushViewController(vc, animated: true)
}
func navigateToTabBar(){
let vc = TabBarCoordinator(navigationController: navigationController)
childCoordinators.append(vc)
vc.start(type: .LoginSession)
}
}
我的标签栏协调器有单独的协调器为每个页面部分这是我的标签栏协调器:
class TabBarCoordinator: Coordinator {
var childCoordinators = [Coordinator]()
var navigationController: UINavigationController
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}
func start(type: NavigationType) {
let vc = NewsFeedTBC.instantiate(storyboard: .newsfeed)
//TODO: check the need of assigning this navigation controller
vc.coordinator = self
//TopRated VC Related
let topRatedNavigationController = UINavigationController()
topRatedNavigationController.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 0)
let topRatedCoordinator = TopRatedCoordinator(navigationController: topRatedNavigationController)
topRatedCoordinator.start()
//Bookmarks VC Related
let bookmarksNavigationController = UINavigationController()
bookmarksNavigationController.tabBarItem = UITabBarItem(tabBarSystemItem: .bookmarks, tag: 1)
let bookmarksCoordinator = BookmarksCoordinator(navigationController: bookmarksNavigationController)
bookmarksCoordinator.start()
//Downloads VC Related
let downloadsNavigationController = UINavigationController()
downloadsNavigationController.tabBarItem = UITabBarItem(tabBarSystemItem: .downloads, tag: 2)
let downloadsCoordinator = DownloadsCoordinator(navigationController: downloadsNavigationController)
downloadsCoordinator.start()
vc.modalPresentationStyle = .fullScreen
vc.viewControllers = [
topRatedNavigationController,
downloadsNavigationController,
bookmarksNavigationController
]
type == .LoginSession ? navigationController.present(vc, animated: true, completion: nil) : navigationController.pushViewController(vc, animated: true)
}
}
例如,这是上面提到的个人协调员:
class BookmarksCoordinator: Coordinator {
var childCoordinators = [Coordinator]()
var navigationController: UINavigationController
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}
func start() {
let vc = BookMarksVC.instantiate(storyboard: .newsfeed)
vc.coordinator = self
navigationController.pushViewController(vc, animated: true)
}
func navigateToProfile(){
let vc = ProfileVC.instantiate(storyboard: .newsfeed)
vc.coordinator = self
navigationController.present(vc, animated: true, completion: nil)
}
}
当我尝试从这些单独的控制器中移动时,出现问题。
1条答案
按热度按时间w6lpcovy1#
找到了我要找的问题。