I am trying to add an array of 2 buttons to the right of a navigation bar, but I get a exception when I run the code.
'NSInvalidArgumentException', reason: '-[UIButton isSystemItem]: unrecognized selector sent to instance
My code is pretty simple really:
UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,100,45)];
label.backgroundColor=[UIColor clearColor];
label.text = @"Test 2 Buttons";
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(00.0f, 0.0f, 32.0f, 32.0f);
UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(00.0f, 0.0f, 32.0f, 32.0f);
NSArray *rightBarButtons = [[NSArray alloc] initWithObjects:button2, button1, nil];
UINavigationItem* navItem = self.navigationItem;
navItem.titleView = label;
navItem.rightBarButtonItems = rightBarButtons;
[rightBarButtons release];
[label release];
I am running it on the iPhone 5.0 simulator. Any idea?? Thanks in advance. Al
You can't directly add UIButtons
. You need to wrap them as UIBarButtonItems
first - there is no compiler warning since you are only passing an array.
Create the bar button items using initWithCustomView:
, passing in your button as the custom view. Or, depending on what is in your buttons, create bar button items directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With