Material: Is PageTabBarController possible to dynamicly arrange view controllers?

Created on 21 Nov 2016  路  13Comments  路  Source: CosmicMind/Material

I want to insert or delete view controllers corresponding to user operation.
Is it possible?
The error message popped out while doing so.
The number of view controllers provided (3) doesn't match the number required (1) for the requested transition

help wanted

All 13 comments

Have you tried this function:

open func setViewControllers(_ viewControllers: [UIViewController], direction: UIPageViewControllerNavigationDirection, animated: Bool, completion: ((Bool) -> Void)? = nil)

It allows you to set the Array of UIViewControllers.

yes, I have tried.
I initialized a PageTabBarController with one root view controller,then i used that function to set three UIViewControllers (Array). I got that error message above.

Okay, I will take a look. I am planning to update the PageTabBar this week, so I will investigate today to help you out, and then release a new PageTabBar. Thanks :)

Thank you very much.I'll be waiting to hear from you.

Hey, I didn't forget about this issue. I will be able to focus on it within the next couple days. Sorry for any delays.

Thank you very much!!!

the same error The number of view controllers provided (3) doesn't match the number required (1) for the requested transition appears again.

Hi, I need your help! I can't rewrite the amount of viewControllers with method

 open func setViewControllers(_ viewControllers: [UIViewController], direction: UIPageViewControllerNavigationDirection, animated: Bool, completion: ((Bool) -> Void)? = nil)

@asyl Yes, this is in the queue to fix. I was working on launching Motion. Will be updated soon.

_For reference_
I found the way how to add dynamically view controllers.
First, redefine property viewControllers of PageTabBarController with your viewControllers.
Second, use

open func setViewControllers(_ viewControllers: [UIViewController], direction: UIPageViewControllerNavigationDirection, animated: Bool, completion: ((Bool) -> Void)? = nil)

to show the page you want. Simply:

pageTabBarController.viewControllers = viewControllers
pageTabBarController.setViewControllers([viewControllers[0]], direction: .forward, animated: true)

@asyl Thank you for sharing. I am working on an update to simplify switching view controllers. Your reference is very helpful :)

You can now use the selectedIndex property to select a tab in Material 2.6.2. For example:

pageTabBarController.selectedIndex = 3

Thank you!

@danieldahan Thanks a lot. I 'll try it later :)

Was this page helpful?
0 / 5 - 0 ratings