Alex Kalinin Alex Kalinin - 8 days ago 3
Swift Question

Swift tabbed app using same UIViewController multiple times

I need a way to add instances of the same UIViewController (from my storyboard) multiple times to the tabbarcontroller

Not sure what the best approach would be

Answer

create different instance on same view controller and add to tabbar controller .

let vc = self.storyboard.instantiateViewControllerWithIdentifier(“storyboard_id”) as yourViewcontroller
vc.tabBarItem = UItabbarItem(Title:“title” image:image tag:yourtag);

let vc1 = self.storyboard.instantiateViewControllerWithIdentifier(“storyboard_id”) as yourViewcontroller
vc1.tabBarItem = UItabbarItem(Title:“title1” image:image1 tag:yourtag);

tabbarController.setViewControllers([vc,vc1]);