UIViewController: setToolbarItems vs navigationItem
Posted
by
Paul Sanwald
on Stack Overflow
See other posts from Stack Overflow
or by Paul Sanwald
Published on 2010-12-28T03:43:46Z
Indexed on
2010/12/28
3:54 UTC
Read the original article
Hit count: 185
iphone
|objective-c
my application has a UIViewController subclass which is being managed by a UINavigationController.
In the viewDidLoad of my UIViewController subclass, I was attempting to add a UIBarButtonItem to the toolbar like this:
settingsButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings"
style:UIBarButtonItemStylePlain target:self action:@selector(viewSettings:)];
[self setToolbarItems:[NSArray arrayWithObject:settingsButton]];
this wasn't working out for me, so after some googling around, I tried this:
[[self navigationItem] setRightBarButtonItem:settingsButton];
which worked out fine. from reading the UIViewController documentation, I'm still confused about why setToolbarItems wasn't working. I verified in the debugger that the button was in the toolbarItems array in the viewDidAppear method. the button itself just wasn't appearing on my toolbar.
so, my question is, why didn't setToolbarItems work for me in the first code snippet?
I don't have the toolbar configured in my xib for this view controller at all, if that makes a difference.
© Stack Overflow or respective owner