Set UIBarButtonItem to a UIBarButtonSystemItem programmatically

ios, uibarbuttonitem

Solution

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.

Problem

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.

Original source