开发者

toolbarItems not being pushed with view

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] pushViewCon开发者_StackOverflowtroller: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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜