我有一个 TabBarCoordinator,它包含一个 UITabBarController。
我想添加两个 UINavigationController(CoinPage 和 Top/Flop),但只有一个显示在选项卡中。我以为我已经以正确的方式设置了一切,我尝试了其他一些东西,但我无法让它工作。
这是我的代码:
class TabBarCoordinator: Coordinator {
var dependencys: DependencyManager
let tabBarController: UITabBarController
var tabCoordinators = [Tabs: Coordinator]()
var navigationController: UINavigationController
init(navigationController: UINavigationController, persistenceCentral: PersistenceCentral, dependencys: DependencyManager) {
self.tabBarController = UITabBarController()
self.navigationController = navigationController
self.dependencys = dependencys
var controllers: [UIViewController] = []
tabCoordinators[.topFlop] = TopFlopCoordinator(navigationController: navigationController, dependencys: dependencys)
tabCoordinators[.coinPage] = CoinPageCoordinator(dependencys: dependencys, navigationController: navigationController)
let coinPageVC = tabCoordinators[.coinPage]!.navigationController
coinPageVC.tabBarItem = UITabBarItem(title: "Coinpage", image: nil, tag: 0)
let topFlopVC = tabCoordinators[.topFlop]!.navigationController
topFlopVC.tabBarItem = UITabBarItem(title: "Top/Flop", image: nil, tag: 1)
controllers.append(topFlopVC)
controllers.append(coinPageVC)
tabBarController.viewControllers = controllers
tabBarController.tabBar.isTranslucent = false
tabCoordinators[.topFlop]?.start()
tabCoordinators[.coinPage]?.start()
}
func start() {
}
}
我做了一些研究,例如他以类似的方式设置选项卡: https ://medium.com/@satindersingh71/uitabbarcontroller-programmatically-2a3df63607f1
所以我不明白为什么它不起作用。