Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dant19

macrumors member
Original poster
May 28, 2008
36
0
I am trying to update my application so that it has multiple views (it currently only has one).

I have a UIViewController called "viewSwitcher" and then 3 other view controllers that manage their own views.

In the app delegate I have made the "viewSwitcher" view a subview of the window, which works fine.

Then in the viewDidLoad method of "viewSwitcher", I insert a new subview as follows:

Code:
MenuViewController *menuController = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];
    menuViewController = menuController;
    
 
    
    [self.view addSubview:menuViewController.view];

Again, this works fine.

Then in the "menuViewController" I have the following method:


Code:
-(IBAction)viewNewGame{

    self.view.hidden = YES;
    [viewSwitcher switchNewGameView];
}

Which calls the following method from "viewSwitcher":

Code:
-(void)switchNewGameView{
    
  
    NSLog(@"switchNewGameView method starting");
    NewGameViewController *newController = [[NewGameViewController alloc] initWithNibName:@"NewGameViewController" bundle:nil];
    newGameViewController = newController;
    
    
    [self.view addSubview:newGameViewController.view];

    NSLog(@"switchNewGameView method finishing");

    
//    NSString *alertText = [NSString alloc];
//    alertText = [NSString stringWithFormat:@"You scored %d"];
//    UIAlertView *alert = [[UIAlertView alloc]
//                          initWithTitle:@"Game Over" 
//                          message:alertText
//                          delegate:self 
//                          cancelButtonTitle:@"New Game" 
//                          otherButtonTitles: nil];
//    [alert show];
}

You'll notice that there are nslogs and commented out code for a UIAlert - this was to check the method was actually being called - which it is.

But despite the method being executed, the newGameViewController view is not being inserted as a subview of "viewSwitcher"...

Any thoughts? (Will clarify where required :) )

Thanks.

Dan
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
It sounds like you'd be better using a UINavigationController to allow you to push and pop view controllers. You can set it to hidden and not animate the transitions if you want. I say this as it handles all the issues of displaying and hiding the views for you.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.