[英]TabBar Controller With Coordinator Pattern
我一直在关注有关协调器模式的 Paul Hudson 教程,并遇到了一个实例,在该实例中,即使我有导航 controller 实例,我也必须在显示标签栏 controller 后使用标签栏 controller 我无法从一个地方移动到另一个地方其他。
我有一个主要协调员来启动申请流程。
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)
}
}
当我尝试从这些单独的控制器中移出时会出现问题。
找到了我正在寻找的问题。
func start() {
let vc = NewsFeedTabBarVC.instantiate(storyBoard: .NewsFeed)
vc.coordinator = self
vc.sideMenuDelegate = self
//Home VC Related
let homeNavigationController = UINavigationController()
homeNavigationController.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "home"), tag: 0)
let homeCoordinator = HomeNavigator(navigationController: homeNavigationController)
childCoordinators.append(homeCoordinator)
homeCoordinator.avatarDelegate = vc
homeCoordinator.start()
//Friends VC Related
let friendsNavigationController = UINavigationController()
friendsNavigationController.tabBarItem = UITabBarItem(title: nil, image: UIImage(named: "users"), tag: 1)
let friendsCoordinator = FriendsNavigator(navigationController: friendsNavigationController)
childCoordinators.append(friendsCoordinator)
friendsCoordinator.start()
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.