Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different content view controllers #39

Open
PrakashMaharjan opened this issue Feb 5, 2018 · 2 comments
Open

Different content view controllers #39

PrakashMaharjan opened this issue Feb 5, 2018 · 2 comments

Comments

@PrakashMaharjan
Copy link

PrakashMaharjan commented Feb 5, 2018

How can we set content view controller with different view controllers for different index?

@kazuhiro4949
Copy link
Owner

kazuhiro4949 commented Feb 6, 2018

Hi, @PrakashMaharjan

You can use any kind of class inheriting UIViewController to return value in PagingContentViewControllerDataSource
https://github.com/kazuhiro4949/PagingKit#1-prepare-data

Example:

Declaring the values as UIViewController

let data: [(menu: String, content: UIViewController)] = [
    (menu: "menu1", content: FooViewConotrller()),
    (menu: "menu2", content: BarViewController())
]

Declaring an associated value-type Enum for arbitrary typed UIViewControllers.

enum ContentViewController {
    case foo(vc: FooViewConotrller)
    case bar(vc: BarViewConotrller)

    var vc: UIViewController {
        switch data[index].vc {
           case .foo(let vc):
                return vc
           case .bar(let vc):
               return vc
        }
    }
}

let data: [(menu: String, content: ContentViewController)] = [
    (menu: "menu1", content: .foo(vc: FooViewConotrller())),
    (menu: "menu2", content: .bar(vc: BarViewController()))
]


func numberOfItemsForContentViewController(viewController: PagingContentViewController) -> Int {
    return data.count
}
    
func contentViewController(viewController: PagingContentViewController, viewControllerAt index: Int) -> UIViewController {
    return data.content.vc
}

If you have any question, feel free to ask me :)

@camacho91
Copy link

Hello, following this issue, I was able to load different viewcontrollers as datasource. But is there a way to replace the UI for the storyboard scene related to that ViewController in the PagingContentViewController? sorry if the question is too obvious. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants