0

A lot of apps I see on iOS and Android will have tonnes of pages for different characters but all the page layouts are the same. Here is an example of an app that does this.

Now I'm sure they don't write every single page as a UIViewController (if it was for iOS) so what's the best way to go about making something like this? Do they the unique data in a database and then it read it for each individual view controller?

If possible, please relate it to Swift as that's what I'm learning.

Hamish
  • 78,605
  • 19
  • 187
  • 280
TheRapture87
  • 1,403
  • 3
  • 21
  • 31

2 Answers2

0

I'm not sure if I am understanding your question... You usually have several different screens (or ViewControllers) but the data shown in them are dynamic. You can instantiate a class (VC) with different data and load different images, text and every 'screen' will be unique (if you want). You can use databases to store the data to be shown or you can manage data directly in memory data structures, array with dictionaries, for example.

Hope It helped you.

Bisca
  • 6,380
  • 2
  • 19
  • 32
0

I can't speak for android, however for iOS you'll be looking to subclass a UIViewController. This will allow you to create a class that has all the common functionality that all your screens require (layout, color schemes, buttons etc).

You will also want to configure this subclass to accept inputs of the properties that you'll want to change across each individual screen (character name, images, etc). You could easily do this through properties and overriding their setters. Or you'd want to look at subclassing again in order to further override the functionality of the base subclass.

I suggest have you a good look at the Apple Swift documentation on Inheritance & Subclassing.

In terms of data input for the view controllers (character names, images etc), it really depends on how complex this data is.

If it's only simple plain text and resource names, you'll want to look at storing them in a property list file (.plist) that you can load into your code as an NSDictionary or NSArray very easily. This answer should help you get started out how to read/write plist files.

More complicated data will probably require the use of a database, either through Core Data or an external library. However, I usually prefer using a custom storage object that you can write to disk though NSKeyedArchiver.

Community
  • 1
  • 1
Hamish
  • 78,605
  • 19
  • 187
  • 280