Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I am developing a very simple iPhone game with this view hierarchy:

Main Menu View
  └> New Game View
  |    └> Player vs Computer Game View
  |    |    └> Pause View
  |    |    └> End Turn View
  |    |    └> End Game View
  |    | 
  |    └> Player vs Player (offline) Game View
  |         └> Pause View
  |         └> End Turn View
  |         └> End Game View
  |
  └> Information View

My current implementation has a single ViewController that controls every aspect of the user interface and a single XIB file that contains every View of the game.

Is this correct? It looks a bit confusing...
Should i have more ViewControllers and more XIB files? And what's the proper way to make them cooperate?

share|improve this question

migrated from stackoverflow.com Sep 15 '11 at 22:55

This question came from our site for professional and enthusiast programmers.

1 Answer 1

Your view controllers should each handle one area full of content. In the past, the guideline was that a view controller managed a "screenful" of content. That has changed somewhat with UISplitViewController, but the idea remains sound. Even with a split view controller, each of the view controllers involved manages its own view hierarchy and has its own task.

So, if you're using a single view controller for your "main menu view", "new game view", "one player view", and "two player view", you should really think about refactoring. Using separate view controller objects for each of those will simplify your code by limiting each view controller's responsibility to one piece of game functionality. That doesn't mean that you have to have a separate class for every view, though. For example, it might be that your "player v. computer" view controller and "player v. player" view controller are each instances of the same class, but configured differently.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.