XLPagerTabStrip icon indicating copy to clipboard operation
XLPagerTabStrip copied to clipboard

Dynamically add view Controllers and tabs based on server data

Open kevintorch opened this issue 6 years ago • 9 comments

please help me...i want add view controllers and tab text based on my server response... there is no fixed no.. how do i do that

kevintorch avatar Mar 29 '18 06:03 kevintorch

Im currently trying to find a solution for this too.

jobnte avatar Apr 02 '18 02:04 jobnte

Like for a UITableView, there is a function to reload the pager. Just call reloadPagerTabStripView() after you received your data from your server and initialized your UIViewController in func viewControllers(for pagerTabStripController: PagerTabStripViewController)

clementleroy avatar Apr 17 '18 08:04 clementleroy

I have same issue.

we are not able to create dynamic child view in this. If any body find solution than please help me. I am stuck in this problem.

cjbhojani avatar Jun 02 '18 09:06 cjbhojani

This is throwing "Fatal error: Index out of range" when calling reloadPagerTabStripView() function after updating the controllers. The file and line of crash is: ButtonBarPagerTabStripViewController.swift -> collectionView(_: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath: IndexPath) method's first statement: guard let cellWidthValue = cachedCellWidths?[indexPath.row]

vdeep avatar Jun 09 '18 11:06 vdeep

Potential fix here: https://github.com/xmartlabs/XLPagerTabStrip/issues/388

nickbit avatar Jun 24 '18 20:06 nickbit

Just create an EmptyChildViewController.swift:

import UIKit
import XLPagerTabStrip

class EmptyChildViewController: UIViewController, IndicatorInfoProvider {

    override func viewDidLoad() {
        super.viewDidLoad()
        // do nothing
    }
    
    func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
        return IndicatorInfo(title: "")
    }
}

set empty child view when your data in not ready

override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        if data.count > 0 {
             // get datas

           return [childVC]
       } 

        let empty = EmptyChildViewController()
        
        return [empty]
    }

daoseng33 avatar Oct 17 '18 09:10 daoseng33

I was able to achieve this, https://stackoverflow.com/a/56563002/9704569

mck694 avatar Jun 15 '19 05:06 mck694

Like for a UITableView, there is a function to reload the pager. Just call reloadPagerTabStripView() after you received your data from your server and initialized your UIViewController in func viewControllers(for pagerTabStripController: PagerTabStripViewController)

How can you make the dynamically created view controller instance conform to the IndicatorInfoProvider protocol?

Isuru-Nanayakkara avatar Apr 15 '20 03:04 Isuru-Nanayakkara

Reference

stack over flow link is not working

Arshad-iOSDeveloper avatar Oct 04 '23 06:10 Arshad-iOSDeveloper