Fixed that tabs got created multiple times and therefore sometimes initial navigation bar title, "Accounts", got displayed (issue was i set them up in viewWillAppear() instead of viewDidLoad())
This commit is contained in:
parent
147ce950f7
commit
7bd6d750a4
|
@ -11,11 +11,15 @@ class TabBarController : UITabBarController, UITabBarControllerDelegate {
|
||||||
|
|
||||||
self.delegate = self
|
self.delegate = self
|
||||||
|
|
||||||
|
setupTabs()
|
||||||
}
|
}
|
||||||
|
|
||||||
override func viewWillAppear(_ animated: Bool) {
|
override func viewWillAppear(_ animated: Bool) {
|
||||||
super.viewWillAppear(animated)
|
super.viewWillAppear(animated)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private func setupTabs() {
|
||||||
let accountsTab = buildControllerAndTabBarItem("Accounts", "accounts", AccountsTab(data: data))
|
let accountsTab = buildControllerAndTabBarItem("Accounts", "accounts", AccountsTab(data: data))
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,6 +32,7 @@ class TabBarController : UITabBarController, UITabBarControllerDelegate {
|
||||||
|
|
||||||
self.viewControllers = [accountsTab, newOptionsTab, settingsTab]
|
self.viewControllers = [accountsTab, newOptionsTab, settingsTab]
|
||||||
|
|
||||||
|
|
||||||
if let firstViewController = viewControllers?.first {
|
if let firstViewController = viewControllers?.first {
|
||||||
DispatchQueue.main.async { // wait till views are created before setting their title and navigation bar items
|
DispatchQueue.main.async { // wait till views are created before setting their title and navigation bar items
|
||||||
self.setNavigationBarForViewController(firstViewController)
|
self.setNavigationBarForViewController(firstViewController)
|
||||||
|
@ -35,7 +40,6 @@ class TabBarController : UITabBarController, UITabBarControllerDelegate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private func buildControllerAndTabBarItem<Content: View>(_ title: String, _ imageName: String, _ view: Content) -> UIViewController {
|
private func buildControllerAndTabBarItem<Content: View>(_ title: String, _ imageName: String, _ view: Content) -> UIViewController {
|
||||||
return buildControllerAndTabBarItem(title, UIImage(named: imageName), view)
|
return buildControllerAndTabBarItem(title, UIImage(named: imageName), view)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue