views:

256

answers:

1

I have a NavigationController based iPhone app that has a navigationBar and a toolbar. Here is basically how it works:

The applicationDelegate pushes a "SplashScreen" onto the RootViewController as a modal view. While the splash screen is up, the application does some work and based on the user's location will either just dismiss the modal view OR will dismiss the modal view and push another view onto the navigation stack.

Both the RootViewController and the child view have toolbars with an Add button. My problem is this: when the 2nd view is pushed automatically, the Add button calls the code for its PARENT controller. If you dismiss this and then press the add button again, it calls the correct code.

Here is some of my code.

in the viewDidLoad of the RootViewController I have:

addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addClicked:)];
    [self setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];

in the viewDidLoad of the Child Controller (LocationListsController) I have:

addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addClicked:)];
    [self setToolbarItems:[NSArray arrayWithObjects:addButton, nil]];

(yes the same code, they both have addClicked events)

in the RootViewController, viewWillAppear is where I actually push the child view:

if (((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex != -1)
    {
        GeoLocation *location = [((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).locations objectAtIndex:((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex];
        ((GeoListsAppDelegate *)[[UIApplication sharedApplication] delegate]).selectedIndex = -1;

        if (lController == nil)
        {
            LocationListsController *aController = [[LocationListsController alloc] initWithLocation:location];
            self.lController = aController;
            [aController release];
        }

        [[self navigationController] pushViewController:lController animated:YES];
    }

The pushing of the view works fine. The only problem I have is the addButton on the toolbar. Does anyone have any ideas?

A: 

Try pushing the "child" view controller from viewDidAppear instead of viewWillAppear.

gerry3
I swear I had tried that, but I just went in and did it again and it worked! Thanks!
David