0

i'm working with the third party lib XLPagerTabBarStrip. it has delegate

override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController]

Now i'm trying to pass my array that contains the storyboard identifiers names. I'm running for loop to get the name and than pass that to my return statement. When i run the app it shows only last item of array. How can i pass all items of array to the return statement? My code is this,

var child1 = UIViewController()

 override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {

    let viewController = ["LoggedInVC","RegisterationVC"]

    for items in viewController{
        child1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: items)

    }
    return [child1]
}

When i run the app it only shows vc with identifier RegisterationVC. How can i show both at once?

Kamran
  • 13,636
  • 3
  • 26
  • 42
raheem
  • 659
  • 2
  • 8
  • 16

1 Answers1

3

Your var child1 is of type UIViewController and you override this variable every time your loop is executed.

What you need is an Array of UIViewController

Try this:

 override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {

    var childs = Array<UIViewController>()

    let viewControllers = ["LoggedInVC","RegisterationVC"]

    for item in viewControllers {
        childs.append(UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: item))
    }

    return childs
}
Teetz
  • 2,647
  • 2
  • 19
  • 28
  • if i have dynamic array , can this be done by this method? @Teetz – raheem Jun 05 '18 at 07:37
  • @raheem What do you concretely mean with dynamic array? (You can edit your question if you want to provide more information) – Teetz Jun 05 '18 at 07:43
  • no i'm just asking that if i had dynamic array than this method could be written? @Teetz – raheem Jun 05 '18 at 07:44
  • just fill the array of identifiers which you need depending on what you want to achieve. – Teetz Jun 05 '18 at 07:46