0

Relevant Data:

I'm making a simple game, using OpenglES. The game itself is done, however I would like to have a main menu as well as some other screens designed in IB. So far I have a death/score screen that is displayed with a simple modelviewcontroller.

I haven't done a ton with GUI building or much programming on the platform outside of C code (posix sockets) and some examples from some books. So I'm not sure how I would go about having lots of views- usually I just use a model view, and it's gotten me along just fine so far. However I don't think that would be the best route here.

Situation:

I have a view controller that shows my main menu- the main menu branches off to the main game, a settings screen, and a high score screen. The main game is made in opengl, and I haven't made the settings view yet, but it likely will be as well. How should I switch between the views? Presenting the main view from the app delegate is as simple as setting the root view controller = newly created view controller, should I do the same thing here? If I do that can I remove the resources from the menu view controller?

Sorry if this is an extremely simple question, I just don't quite get the process.

Avlagrath
  • 125
  • 4

4 Answers4

1

I'm not entirely sure what you want to do, but an easy way to show a new view controller is:

SecondViewController *aSecondViewController = [[SecondViewController alloc]
initWithNibName:@"SecondView" bundle:nil];
[self presentModalViewController:aSecondViewController animated:YES];

I hope that helps.

gurooj
  • 2,100
  • 4
  • 21
  • 25
  • I've been using the presentmodalviewcontroller method, I just wasn't sure if it was the best route... – Avlagrath Dec 06 '11 at 01:50
  • The best route depends on what kind of effect you want when presenting the view. If you tell us what you want then we can give you better advice. – sosborn Dec 06 '11 at 01:53
  • The only other "easy" way to show a different view controller is to push a view controller onto a navigation controller. That is how you get the arrow type back button in the upper left of iPhone apps. – gurooj Dec 06 '11 at 01:56
1

How should I switch between the views?

In the vast majority of cases, you should be using a UINavigationController. Your initial controller would be the main menu. When you want to go into a particular section of your application, you push a new view controller onto the stack. When you want to come back out, you pop it off the stack.

Jim
  • 72,985
  • 14
  • 101
  • 108
  • 1
    I see, since I have a game, and I should be worrying about resources, is there anything extra I should do when displaying my game view? – Avlagrath Dec 06 '11 at 01:51
  • There's nothing out of the ordinary. If you're expecting to use a lot of memory, make sure you handle memory warnings in your view controllers. Make sure you use the static analyser and check for memory leaks, etc. You shouldn't be worried about resources because it's a game, you should be worried about resources because it's a mobile platform - the same would apply to any application, not just games. – Jim Dec 06 '11 at 02:01
1

Besides navigation and presenting modally that others have mentioned, another option is to swap out views. May or may not fit your app's flow but wanted to point out another option for you to consider

Best practice for switching iPhone views?

Community
  • 1
  • 1
bryanmac
  • 38,941
  • 11
  • 91
  • 99
0

If you are already limiting the game to iOS 5 for some other reason you should look into UIStoryboard. If you don't currently require iOS5 the "simplest" way is to use table views, but that isn't a very "gamey" UI.

Stripes
  • 4,161
  • 2
  • 25
  • 29