I need two buttons on the left side of the navigation bar. The only way I figured out how to do this is to put them in the UIToolbar first and then set the leftBarButtonItem element for it.
If I do this, it works fine (you can see that it stands out when pressed):
UIBarButtonItem* myBtn = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStyleBordered target:self action:@selector(doSomething:)]; self.navigationItem.leftBarButtonItem = myBtn;
But if I do this, the action of the button still happens, but there is no selection (there is no visual feedback that you click on the button):
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2]; UIBarButtonItem* myBtn = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStyleBordered target:self action:@selector(doSomething:)]; UIBarButtonItem* myBtn2 = [[UIBarButtonItem alloc] initWithTitle:@"Button2" style:UIBarButtonItemStyleBordered target:self action:@selector(doSomethingElse:)]; [buttons addObject:myBtn]; [buttons addObject:myBtn2]; UIToolbar* toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 133, 44)]; [toolbar setItems:buttons animated:NO]; self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:toolbar];
Any idea why this causes the buttons to not stand out when touched?
source share