Ryan Hampton Ryan Hampton - 5 months ago 124
Swift Question

Swift: How to show child view controllers via storyboard rather than programmatically using XLPagerTabStrip

I have been following the XLpagerTabStrip cocoapods extension to set up a tab bar at the top of my view controller (https://github.com/xmartlabs/XLPagerTabStrip). I am implementing the ButtonBarPagerTabStripViewController and have followed the steps exactly, but the UIScrollView is not displaying the child view controllers.

I think this is because in the example the child view controllers are set up programmatically rather than in the storyboard, whereas mine are currently set up in the storyboard, and hence are displaying no content, yet there is no way that I can see to connect the child view controllers to the ButtonBarController via the storyboard.

Is there a way to display the child view controllers using the storyboard, or must it be done programmatically?

The GitHub page says to implement the following function (But this doesnt seem to work if your child view controllers are set up via the storyboard):

override public func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController]
{
return [MyChildViewController(), MySecondChildViewController()]
}

Answer

You need to load controller from storybard:

override public func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController]
{
    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let childOneVC = storyboard.instantiateViewControllerWithIdentifier("childOneVC")
    let childTwoVC = storyboard.instantiateViewControllerWithIdentifier("childTwoVC")
    return [childOneVC, childTwoVC]
}