swiftxlpagertabstrip

Ho to hide Childe View Controller of ButtonBarPagerTabStripViewController on segment index chnage


Hi I am using ButtonBarPagerTabStripViewController for pager, on segment controller index change

i want hide one child view controller of ButtonBarPagerTabStripViewController.

I used

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

this delegate method to add view controller in ButtonBarPagerTabStripViewController.

How can hide any child view controller of ButtonBarPagerTabStripViewController.


Solution

  • To add your UIViewController to your pagerTabStripController you should have something like :

    // MARK: - XLPagerTabStrip required override methods
    
    override public func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        return buildViewControllers()
    }
    
    // Build the tabs in the tabBar.
    func buildViewControllers() -> [UIViewController] {
    
        // Add custom viewControllers here.
    
        let aViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "YOUR_IDENTIFIER") as! YOUR_VIEW_CONTROLLER
        let bViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "YOUR_IDENTIFIER") as! YOUR_VIEW_CONTROLLER
    
        // Other...    
    
        return [aViewController, bViewController]
    }
    

    To hide a specific UIViewController just remove it from the UIViewController array, and call the delegate method again with reloadPagerTabStripView() to reload the tabs