Using Multiple Views

Posts: 16
Joined: 2010.01
Post: #1
My iPhone App is a child's game and I have about 20 different views that I want to randomly switch between. Now I have watched Nick Myers'
iPhone Tutorial - Multiple XIB files on Vimeo (, however, he is only switching between two views & nibs and does not release the first viewController. I have tried to set-up my app in this manner and get it to switch fine enough, but I must be doing something wrong still, because it isn't releasing the view controllers.

Could someone please explain why I need to have ViewControllers & Views for each XIB instead of just putting all the code in the ViewControllers and forgetting the views altogether? I have the code for switching the views in the AppDelegate file, is this a good way?

Also, I have multiple sounds for each view...where is the best place to put the code for my sounds?

Here is where I have the sounds right now:

(in the viewController.m file)
- (void)viewDidLoad {

    //the following lines of code create and initialize the sounds
    NSBundle *mainBundle = [NSBundle mainBundle];
    NSURL *eyesURL = [NSURL fileURLWithPath:[mainBundle pathForResource:@"eyes" ofType:@"aiff"]];
    eyesPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:eyesURL error:nil];
    [eyesPlayer prepareToPlay];
    NSURL *mouthURL = [NSURL fileURLWithPath:[mainBundle pathForResource:@"mouth" ofType:@"aiff"]];
    mouthPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:mouthURL error:nil];
    [mouthPlayer prepareToPlay];
    NSURL *noseURL = [NSURL fileURLWithPath:[mainBundle pathForResource:@"nose" ofType:@"aiff"]];
    nosePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:noseURL error:nil];
    [nosePlayer prepareToPlay];

Quote this message in a reply
Posts: 283
Joined: 2006.05
Post: #2
Generally you don't release view controllers. You often don't need to release the views either; by default the controller will respond to low memory warnings by releasing the view, then recreating it when it's called for. This is nice because it keeps navigation smooth where possible.

There are lots of reasons you might want to override this, but the default behaviour is often good enough.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Multiple Views MacSteve85 0 2,640 Feb 1, 2010 05:53 PM
Last Post: MacSteve85
  Advice regarding Views & Touches for iPhone game Elphaba 5 5,489 Jul 17, 2009 01:54 PM
Last Post: Frank C.
  Navigation of views in view base application trygametest 0 3,179 Feb 20, 2009 06:12 AM
Last Post: trygametest