Iphone – Programmatically changing the identifier property of UIBarButtonItem

cocoa-touchiphoneuibarbuttonitem

Through Interface Builder I have the ability to change the Identifier of a UIBarButtonItem to something like "Add" (or "Undo", "Redo" etc…). This gives my button a nice "+" image.

How can I set this programatically? The UIBarButtonItem does not accept a "setIdentifier" message.

Best Answer

Once constructed, a UIBarButtonItem's "Identifier" can not be modified. However, the UI can be changed by replacing the button with a programmatically constructed variant. For example:

UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                                                                           target:self 
                                                                           action:@selector(doAddAction:)];