xmartlabs / XLPagerTabStrip

Android PagerTabStrip for iOS.
MIT License
6.97k stars 1.33k forks source link

XLPagerTabStrip - Programatically going to particular tab with index value provided is not working #779

Open ekshithavyshnavi opened 4 years ago

ekshithavyshnavi commented 4 years ago

XLPagerTabStrip - Programatically going to particular buttonbar tab with index value provided is not working it is showing default first buttonbar tab. if I call 4th or 5th buttonbar tab programatically it is coming up with default first buttonbar tab.

  1. moveToViewController(at: Index) - given in my listingviewcontroller

  2. where I get index from is as below :

    @IBAction func listingButtonTapped(_ sender: Any) {

    if let tap = sender as? UITapGestureRecognizer, let tag = tap.view?.tag {
        print(tag)
    
        let Index = tag
    
            router?.routeToListings(at: Index) --> this goes to my listingviewcontroller
    }

    }

  3. my listingviewcontoller has TableChildExampleViewController it is defined as below:

class ListingViewController: ButtonBarPagerTabStripViewController { override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { let child_0 = TableChildExampleViewController(style: .plain, itemInfo: "ALL") let child_1 = TableChildExampleViewController(style: .plain, itemInfo: "EVENTS") let child_2 = TableChildExampleViewController(style: .plain, itemInfo: "PROMOTIONS") let child_3 = TableChildExampleViewController(style: .plain, itemInfo: "ATTRACTIONS") // let child_4 = TableChildExampleViewController(style: .plain, itemInfo: "INTERACTIVE TRAILS") let child_4 = TableChildExampleViewController(style: .plain, itemInfo: "DINING") let child_5 = TableChildExampleViewController(style: .plain, itemInfo: "HOTEL & SPAS") let child_6 = TableChildExampleViewController(style: .plain, itemInfo: "RETAIL & SERVICES")

    child_0.tableView.delegate = self
    child_1.tableView.delegate = self
    child_2.tableView.delegate = self
    child_3.tableView.delegate = self

// child_4.tableView.delegate = self child_4.tableView.delegate = self child_5.tableView.delegate = self child_6.tableView.delegate = self

    guard isReload else {
        return [child_0, child_1, child_2, child_3, child_4, child_5, child_6]
    }

    var childViewControllers = [child_0, child_1, child_2, child_3, child_4, child_5, child_6]

    for index in childViewControllers.indices {
        let nElements = childViewControllers.count - index
        let n = (Int(arc4random()) % nElements) + index
        if n != index {
            childViewControllers.swapAt(index, n)
        }
    }
    let nItems = 1 + (arc4random() % 7)
    return Array(childViewControllers.prefix(Int(nItems)))
}

override func reloadPagerTabStripView() {
    isReload = true
    if arc4random() % 2 == 0 {
        pagerBehaviour = .progressive(skipIntermediateViewControllers: arc4random() % 2 == 0, elasticIndicatorLimit: arc4random() % 2 == 0 )
    } else {
        pagerBehaviour = .common(skipIntermediateViewControllers: arc4random() % 2 == 0)
    }
    super.reloadPagerTabStripView()
}

}

  1. My same code is working with old XLPagerTabStrip version i.e 7.0 which supports Swift 3 and is not working with XLPagerTabStrip 9.0 version recently I moved my project to Swift 5 version so I had to update XLPagerTabStrip to 9.0 to resolve version error and this code is not working. I cannot view my selected bar when I call programatically from listingButtonTapped Action call. Please provide me solution for this.

Note:-