0

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?

2 Answers 2

4

[self.navigationController.visibleViewController setToolbarItems:@[button1, button2, button3]];

Seems to work if you set the ToolbarItems on the visibleViewController.

1
  • This helped me! Why is the method also on UINavigationController and why do we need the method on visibleViewController?
    – Tim Baas
    Dec 21, 2013 at 17:48
0

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];
2
  • 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 Sep 22, 2010 at 13:45
  • 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.. Sep 23, 2010 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.