Greg Peckory
Greg Peckory

Reputation: 8068

Using same ViewController for different Page Views Swift

I am new to Page Views, so stay patient.

Up till now all the tutorials I've seen show you how to set up different unique ViewControllers for different Pages in a PageViewController.

I am setting up a 3-day news feed, and so I decided that swiping between each page would cause the user to switch between the days.

So each page will be absolutely identical in terms of UI but different in terms of Data.

So I should be able to point each Page to the same viewController but to a different data source.

My data source will be a 2-D Array. Yes, you guessed it, 2-D to separate the days ! Each Column represents a day, and the corresponding Row will be a table view in its respective page.

Is there no simple way to make this data source (array) accessible by all Pages, (initialise in PageViewController), and let each Page point to the same ViewController, and edit their respective table views accordingly.

Thanks for the help !

Upvotes: 3

Views: 956

Answers (1)

matt
matt

Reputation: 535954

Is there no simple way to ... and let each Page point to the same ViewController

No, not to one and the same View Controller instance. But they can certainly be different instances of the same View Controller class. That, in fact, is quite normal. It's just a matter of configuring the view controller properly each time it is created, for the "page" it is to display.

What you're really asking for is just cleaner configuration (or configuration that you feel is cleaner). Then write cleaner configuration, whatever that means to you! There is no reason in the world, for example, why your view controller instance should not somehow be told, on instantiation, what page it is portraying, and configure itself accordingly based on that.

Upvotes: 5

Related Questions