dalezak/turbo-ios-base

Tabbar button issue

Opened this issue · 2 comments

I am having an issue with the Tabbar buttons. The page loads when you click on the button, but the button does not change to the active state. It looks like it does for a second and then immediately changes back to the home button. Anyone else seeing this issue?

tmac commented

Yep, I experienced same. I am NOT a swift dev, so use this at your own risk, but here's my fix.

Add the following at the very top of the loadTabs function.

    func loadTabs(_ authenticated: Bool = false) {
        var selectedTabIndex = 0
        if let selectedTabBarItem = tabBar.selectedItem {
            selectedTabIndex = tabBar.items?.firstIndex(of: selectedTabBarItem) ?? 0
        }
       ....
      ....
   }

Then in the same function change:

   if (tabBar.items!.count > 0) {
      tabBar.selectedItem = tabBar.items![0]
   }

To:

   if (tabBar.items!.count > 0) {
      tabBar.selectedItem = tabBar.items![selectedTabIndex]
   }

Pretty sure that was the whole change. And I'm very interested to see if someone has a better solution.

That worked for me, thank you for sharing! I am not a swift dev either, just getting into mobile dev, but that looks like a good solution, you should throw that up on a PR.