views:

60

answers:

1

Hi, I'm a newbie to iPhone coding and am having problems with the UINavigation control.

I have 3 views (main menu, news and login). The main menu is my base view in the root controller and then I push the login or news views onto the stack when the user clicks the button from the main menu. However, if I am on the news screen and want to switch to the login view, I would expect to pop the current view (takes me back to the main menu), and push the login view. However, this does not happen and I'm not sure why...

Here is the code from my AppDelegate:

@synthesize window;
@synthesize rootController;


- (void)applicationDidFinishLaunching:(UIApplication *)application {    

// Override point for customization after application launch
 [window addSubview:rootController.view];
[window makeKeyAndVisible];
}


- (IBAction)loadLoginView
{
 [self loadMainMenuView];
 LoginViewController *loginView = [[LoginViewController alloc] initWithNibName:@"LoginView" bundle:nil];
 [rootController pushViewController:loginView animated:YES];
 [loginView release];
}

- (IBAction)loadNewsView
{
 [self loadMainMenuView];
 NewsViewController *newsView = [[NewsViewController alloc] initWithNibName:@"NewsView" bundle:nil];
 [rootController pushViewController:newsView animated:YES];
 [newsView release];
}

- (IBAction)loadMainMenuView
{
 [rootController popToRootViewControllerAnimated:YES];
}

- (void)dealloc {
[window release];
 [rootController release];
[super dealloc];
}

Can anyone see what I'm doing wrong? Is there a better way to manage this? Thanks!

+1  A: 

Performing two animated viewController changes on the navigation controller does not work properly (these are not queued). Try the following:

- (IBAction)loadNewsView {
 [self loadMainMenuView];
 NewsViewController *newsView = [[NewsViewController alloc] initWithNibName:@"NewsView"     bundle:nil];
 [rootController pushViewController:newsView animated:YES];
 [newsView release];
}

Alternatively you can listen to viewDidAppear in the navigationController's root viewController and only push the new viewController once the root has reappeared. You will probably need to use some BOOL to not always present the news viewcontroller when the root appeared. Hope this makes sense.

Felix
Thanks Felix,I tried removing the animation off the popallviews code and that worked... However then I was left without the transition effect. I'm now trying to see if I can do it without the NavigationController and just manage the views manually.Thanks again!
Rob Taylor