UIBarButtonItemStyleDone does not create blue buttons in navigation bar when controller is pushed
Asked Answered
G

1

7

I've searched around on several different forums and can't seem to find an answer for this. I have added a bar button item to a navigation controller and set its style to UIBarButtonItemStyleDone. When this is the first controller on the navigation stack, the button properly shows up blue. However, when the controller is created and pushed onto the stack, the style is ignored and it shows up black.

I know that this problem occurs when the tintColor has been changed, but I am using the standard UIBarStyleBlack and not setting tintColor. I've tried setting tintColor to nil, as well, but that doesn't work either.

Relevant code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.navigationItem.rightBarButtonItem =
    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                  target:self
                                                  action:@selector(createNew:)];
    self.navigationItem.rightBarButtonItem.style = UIBarButtonItemStyleDone;
}

Any ideas or workarounds would be greatly appreciated.

Gide answered 23/11, 2010 at 0:19 Comment(0)
R
10

You're using a preset system item, for which the style property does nothing. You need to either switch to the actual UIBarButtonSystemItemDone system item (which is blue, but says "Done"), or switch to using either -initWithImage:style:target:action: or -initWithTitle:style:target:action: and supplying your own image or text.

Rm answered 23/11, 2010 at 0:43 Comment(3)
The button will show up as blue, so the style property must do something, it just shows up as blue inconsistently.Gide
Nevertheless, grahamparks is right - use the Done system item.Jurat
If you do: [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(createNew:)]; it will work. Just as pointed out by grahamparksKayleen

© 2022 - 2024 — McMap. All rights reserved.