views:

130

answers:

1

Hi.

I got the following:

@interface A : UIViewController {
}

@property (nonatomic, assign) UIToolbar *toolBar;
@end

Here the 'toolBar' property can be set from outside to point to a externally created UIToolbar OR it can point to the navigationController tool bar.

I want to set the tool bar items independent of witch tool bar 'toolBar' point's to. I try the following without success:

    NSMutableArray *buttons = ...
    ...
    UIBarButtonItem *item = ...
    [buttons addObject:item];
    ...
//I know this are the same but...
    [self.toolBar setItems:buttons];
    self.toolBar.items = buttons;

Any idea?

A: 

You may be running into this issue because at least in the case where the UINavigationController is involved the toolbar items will be obtained from the UIViewControllers which are pushed onto the stack via their toolbarItems property.

EDITED after comment ...

What I'm saying is that you cannot do this:

self.toolBar = self.navigationController.toolbar;
self.toolBar.items = buttons;

When your view controller is within a UINavigationController you have to do:

self.toolbarItems = buttons; // OR [self setToolbarItems:buttons animated:YES];
imaginaryboy
But if I do: 'self.toolBar = self.navigationController.toolbar'. How can i manage the tool bar items?, the calls that i post in my question doesn't work
GojaN
Post after edited: you are right, set the items of the UINavigationController's tool bar trough an UIToolbar reference doesn't work... I wonder why..
GojaN