Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set UIBarButtonItem to a UIBarButtonSystemItem programmatically

Can I assign a system item to a UIBarButtonItem without having to recreate it? Just calling initWithBarButtonSystemItem on the existing button doesn't seem to work for me.

This is the code in which I try to make it work. I'm trying to improve native controls support for iOS using PhoneGap. That plugin allows changing title/image without problems but I have to figure out how to assign a system-provided icon to the existing button.

like image 273
AndiDog Avatar asked Dec 03 '22 03:12

AndiDog


1 Answers

I took a look at your code, didn't find your use of initWithBarButtonSystemItem. However, this is what I'm doing in a similar case with native iOS programming:

UIBarButtonItem *myButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(done)];

self.navigationItem.rightBarButtonItem = myButton;
[myButton release];

This works correctly for me. I'm not familiar with PhoneGap and it may or may not change things however.

like image 87
Malcolm Avatar answered May 22 '23 09:05

Malcolm