Closed karta88821 closed 6 years ago
Hello @karta88821 👋
Thank you for your question. You've done everything right in the TabBarCoordinator
! You've only missed one small thing:
In order to display MainViewController
with a MainCoordinator
we should pass a navigation controller crated in the TabBarCoordinator
to the MainCoordinator
:
class MainCoordinator: BaseCoordinator<Void> {
init(navigationController: UINavigationController) {
self.navigationController = navigationController
}
override func start() -> Observable<Void> {
...
let viewController = MainViewController.initFromStoryboard(name: "Main")
// ⚠️ IMPORTANT STEP!
navigationController.pushViewController(viewController, animated: false)
...
}
}
And coordinate(to: )
child coordinators in the TabBarCoordinator
:
class TabBarCoordinator: BaseCoordinator<Void> {
override func start() -> Observable<Void> {
...
let mainNav = UINavigationController()
// Setup AccountNavigation
let accountNav = UINavigationController()
...
window.rootViewController = tabBarController
window.makeKeyAndVisible()
let mainCoordinator = MainCoordinator(navigationController: mainNav)
coordinate(to: mainCoordiantor)
.subscribe()
.disposed(by: disposeBag)
let accountCoordinator = MainCoordinator(navigationController: accountNav)
coordinate(to: accountCoordinator)
.subscribe()
.disposed(by: disposeBag)
return Observable.never()
}
}
Hope this helps!
@arthur-here Thanks for your reply!
@arthur-here This implementation is causing memory leak when logging out from Tabbar to login again. Can you provide any tips how to fix it
I try to follow your example, and use the tabbar as the
rootviewtroller
, but after the run app I found that the navigationbar and the tabbar exist, but the view is black, would like to ask where is the problem, it there something wrong withstart ()
method? thanks!I have two tabor items in the tabbarViewController:
And
TabBarCoordinator
is containedMainCoordinator
andAccountCoordinator