YellowPillow
YellowPillow

Reputation: 4270

Transitioning to a new view controller

So this piece of code is called after authenticating the users login details:

func completeLogin() {
        dispatch_async(dispatch_get_main_queue(), {
            let tabBarController = self.storyboard!.instantiateViewControllerWithIdentifier("PostLoginTabBarController") as! UITabBarController
            let tableViewController = self.storyboard!.instantiateViewControllerWithIdentifier("InformationTableViewController") as! InformationTableViewController
            let tableViewNavController = UINavigationController(rootViewController: tableViewController)
            tabBarController.viewControllers?.removeAll()
            tabBarController.viewControllers?.append(tableViewNavController)
            self.presentViewController(tabBarController, animated: true, completion: nil)
        })
    }

In my storyboard:

enter image description here

I have the PostLoginTabBarController that has a relationship with 2 other ViewControllers

My question is:

Is there a better way than removing all the View Controllers that the PostLoginTabBarController has and then adding the new instantiated ones in the completeLogin() method? The reason I am doing this is because if I sever the relationship between the PostLoginTabBarController when the PostLoginTabBarController is presented it shows a black screen, but if I don't sever the relationship then it is fine.

Here is an example when I sever the relationship:

enter image description here

And when I don't:

enter image description here

Upvotes: 0

Views: 24

Answers (1)

David Wong
David Wong

Reputation: 10294

Have you tried using setViewControllers(_ viewControllers: [UIViewController]?, animated animated: Bool) instead of

tabBarController.viewControllers?.removeAll()
tabBarController.viewControllers?.append(tableViewNavController)

Upvotes: 3

Related Questions