Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()]
}
like image 512
Ryan Hampton Avatar asked Jun 13 '16 12:06

Ryan Hampton


1 Answers

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]
}
like image 185
tbilopavlovic Avatar answered Sep 19 '22 17:09

tbilopavlovic