0

I'm implementing a user authentication system for an app. If the user is logged in they get one set of available tabs to select. If They're not logged in they get another. Now the issue I'm running into is that after a user logs in (app redirects to safari to some oauth stuff and then returns to the app), I update the tabs from the UITabBarController like so:

private var accessibleViewControllers = [UIViewController]()

func setUpView() {
    var viewControllersToSet = [UIViewController]()

    if let user = theUser {
        for controller in accessibleViewControllers {
            if !(controller is LogInViewController) {
                viewControllersToSet.append(controller)
            }
        }
    } else {
        for controller in accessibleViewControllers {
            if controller is LogInViewController || controller is HomeNavigator  {
                viewControllersToSet.append(controller)
            }
        }
    }

    setViewControllers(viewControllersToSet, animated: false)
}

Now the funny thing is, the tab icons don't refresh, but I can still click on the spaces where the new icons would be to link through to the associated view. How do I refresh the tabs so that the right icons appear?

kellanburket
  • 12,250
  • 3
  • 46
  • 73

1 Answers1

-1

This was a threading issue. I was loading the user data over a background thread and then calling the delegation method setUpView from the same background thread. To fix this I ran it back on the main queue:

    dispatch_async(dispatch_get_main_queue()) {
        if self.accessibleViewControllers != nil {
            var viewControllersToSet = [UIViewController]()

            if let user = MediatedUser.shared {
                for controller in self.accessibleViewControllers! {
                    if !(controller is LogInViewController) {
                        viewControllersToSet.append(controller)
                    }
                }
            } else {
                for controller in self.accessibleViewControllers! {
                    if controller is LogInViewController || controller is HomeNavigator  {
                        viewControllersToSet.append(controller)
                    }
                }
            }

            self.viewControllers = viewControllersToSet
        }
    }
kellanburket
  • 12,250
  • 3
  • 46
  • 73