override func viewControllersForPagerTabStrip(pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
var controllers = [UIViewController]()
for _ in 0...kinds.count - 1 {
let chid = SecondViewController()
controllers.append(chid)
}
return controllers
}
kinds.count is Child Controllers number but it request from internet ,it is an uncertain number
You can dynamically create any number of child view controllers as you do in the sample code. I create children in a loop as well and it works fine.
@volkanx @dowhilenet Like reusing the same viewconrtoller with different data? check attachment . Is this achievable with this framework?
@khanxc sure, it is possible.
when you create the child view controller you need to assign the data it's going to display. Something like:
let child1 = MenuViewController()
child1.menuItems = [BurgerItem] // Populate the data beforehand
children.append(child1)
let child2 = MenuViewController()
child2.menuItems = [ChickenItem]
children.append(child2)
Same view controller, different data to display
Well explained by @volkanx. I would just add that children is an array of UIViewControllers, therefore in the for loop you need to instantiate let child = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ChildViewController") as! ChildViewController
That works fine for me.
Now the question i have is how can we deallocate some of the ViewControllers we don't need. For example, i would like to have 3 adjacent ViewControllers at the same time (so to keep smooth paging) and the rest should be deallocated so that the memory would be saved. My ViewControllers are quite heavy and thats the reason i would like them to be deallocated.
Any help would be appreciated
Most helpful comment
@khanxc sure, it is possible.
when you create the child view controller you need to assign the data it's going to display. Something like:
Same view controller, different data to display