2

I'm using XLPagerTabStrip to switch among a collection of view controllers. I have three view controllers and I would like that middle view controller is shown by default as first.

I could use

let parentViewController = self.parent! as! ParentViewController
parentViewController.moveToViewControllerAtIndex(1)

inside my first view controller, but that first view controller loads some data from the server and if I switch to another view controller while it is loading data, that first view controller will freeze and it won't load data.

Is there a way to show middle view controller as first by default?

user3593157
  • 47
  • 2
  • 9
  • this is issue in XLPagerTabStrip you can using `pod 'XLPagerTabStrip' , :git => 'https://github.com/Dagogatc/XLPagerTabStrip.git', :branch => 'moveToViewController-issue'` – a.masri Apr 10 '18 at 06:03

6 Answers6

3

jump to the defenition of 'currentIndex' and change it to public from private. then you can select your current controller by this code:

currentIndex = 1
Yasin Patel
  • 5,624
  • 8
  • 31
  • 53
Negar
  • 91
  • 6
3

In function:

 override func viewControllers(for pagerTabStripController: 
      PagerTabStripViewController) -> [UIViewController] {
            // This line will help you achieve the requirement
            pagerTabStripController.currentIndex = /* required index */


   }

It will work smoothly after you make currentIndex in PagerTabStripViewController as public.

Sarthak Sharma
  • 246
  • 2
  • 11
1

To prevent loading the first tab, moveToViewControllerAtIndex() must be called before viewDidLoad() is called in your PagerTabStripViewController subclass.

tuomastik
  • 4,559
  • 5
  • 36
  • 48
0
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
pagerTabStripController.moveToViewController(at: 0) // required index
}
0

For Move Specific Tab XLPagerTabStrip in swift 5

  override func viewDidAppear(_ animated: Bool) {

    if nowFrom == "sendvc"
    {
        self.moveToViewController(at: 3,animated: false)

    }
}
M Murteza
  • 1,629
  • 15
  • 10
0

You have to use the following lines:

  override func viewDidAppear(_ animated: Bool) {

        self.moveToViewController(at: 2)
        reloadPagerTabStripView()
        
    }
Soroush Chehresa
  • 5,490
  • 1
  • 14
  • 29