Sunday, April 18, 2010

Navigation: Fixing toolbars

Toolbars on navigation items


In my previous version of the code, I was loosing my toolbar items when I changed views.  A quick perusal of the documentation reveled that instead of manually configuring the toolbar, I should be setting the toolbarItems property on my class.  (see
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006934-CH3-SW30

So I changed my toolbar from:

- (void) showToolbar:(NSString *) buttonName target:(id) target action:(SEL) action
{
[self.navigationController setToolbarHidden:false];
self.toolbarItems =items;
    UIBarButtonItem *item= [[UIBarButtonItem alloc] initWithTitle:buttonName style:UIBarButtonItemStyleBordered target:target action:action];
NSArray *items = [NSArray arrayWithObjects: item, nil];
self.navigationController.toolbar.items =items;
[item release];
}

So I changed my toolbar to:

- (void) showToolbar:(NSString *) buttonName target:(id) target action:(SEL) action
{
[self.navigationController setToolbarHidden:false];
    UIBarButtonItem *item= [[UIBarButtonItem alloc] initWithTitle:buttonName style:UIBarButtonItemStyleBordered target:target action:action];
NSArray *items = [NSArray arrayWithObjects: item, nil];
self.toolbarItems =items;
[item release];
}

Now it works great, of course now that I still have the first level item on my toolbar, my code crashes when they choose it, because I am maintaining a separate callback for which dialog is active. 


To fix this, instead of having one current dialog variable, I just added two variables listSelectDialog and wordSelectDialog.  Now the code works great.






No comments:

Post a Comment