0

I am new to Swift and didn't find a good explanation when to use a new ViewController and when to use another scene.

Example: You are programming a game with a menu, a level selection screen and the game screen (on which you play the level).

From my understanding, I would be able to program everything with only one ViewController, but multiple scenes (menu, level selection and level)

When (and why) would I use more than one ViewController for that?

Thanks!

Applecow
  • 796
  • 3
  • 13
  • 35
  • i think this link will help you https://stackoverflow.com/questions/31814563/whats-the-difference-between-a-view-and-a-viewcontroller – A.Munzer May 19 '19 at 11:25

2 Answers2

0

Having a different ViewController for different screens (I assume you're talking about SpriteKit) has one main benefit: You can keep all menu screen logic in the menu's ViewController and game/level logic in another one.

I would use the same ViewController class for all levels since the code to handle the game just be used continuously, swapping out SKScenes.

cookednick
  • 1,025
  • 9
  • 16
-1

Very low lvl way to put it...

Each screen of your app is a View and a corresponding ViewController that is the class of that view.

So you go to your storyboard and you place a button and a label. Then you connect those elements to your ViewController class. Now your ViewController is aware that there is a button and a label. Now on ViewController you just have to set a function that says: When I press this button, change my label.

Check this: Storyboard and ViewController

Try to right click the button and drag it to the code, it will do the connection for you.

  • 1
    You completely ignored the part of his question that was about scenes. It's clear he's talking about SpriteKit, which doesn't have much to do with outlets and UIViews. – cookednick May 20 '19 at 19:56