0

Say I want to show 300 words, one in a page, connected by Swipe Gesture or Button. It is definitely feasible to create 300 view controllers in the storyboard and connect them together. But is there a better/faster way to do this without numerous view controllers or xibs? I am a novice here. Thank you for your patience.

Marcy
  • 4,611
  • 2
  • 34
  • 52
  • 1
    Make a property 'text' in a view controller and update that based on something you want – J. Doe Feb 10 '19 at 22:13
  • An easy way to do that is to open a new project as a Page-Based App, read the project comments and modify with your own data. This may not suit your exact needs but should give you a good working example of how one vc can appear to be hundreds. – Marcy Feb 10 '19 at 22:30
  • Thanks @Marcy But I have 300 words, which may be too long for a page control. – Shuichi Feb 10 '19 at 23:40
  • @Shuichi Not a page control but Apple's project type "Page-Based App" which uses a page view controller. Creating a new project with that project type and then running will show you a demo of something very similar to what you seem to be describing. – Marcy Feb 11 '19 at 00:36

2 Answers2

0

You misunderstand how view controllers work. Think of a view controller as a blank form. You instantiate a view controller, then populate it with unique data. Then When you have different data to display, you create a new blank view controller and give it different data to display.

You don't create a separate XIB or storyboard entry for every instance of a view controller. You create a copy each time you need one. If you have different types of forms you need to display then you might define a different XIB/Storyboard entry for each unique TYPE of view controller, but not for each instance of a type.

To get more specific you've going to have to show the layout of your view controller. (Edit your question to provide more info.)

Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Thanks! So what I want to do is I have 300000000 words, starting say from Amy, Bob, etc. You can only see one word in one screen. I want to swipe or click the button to get the next word. Since there are so many words, I don't want to have 300000000 view controllers. How do I do? – Shuichi Feb 11 '19 at 01:37
0

You can use UICollectionView with scrollDirection = .horizontal, where each cell represents a word view. You will need to do some extra work to adjust height and width to make it look like a full screen page on different devices. So, you have a single view controller, and one, reusable collection view cell for words.

There are many online tutorials, you can use to get a basic collection view up and running, and take it up from there.

Swapnil Luktuke
  • 10,385
  • 2
  • 35
  • 58