Search code examples
iphoneiosuibarbuttonitemidentifier

Setting the identifier of a UIBarButtonItem programmatically


I have a UIBarButtonItem item in a xib file. I can set its identifier as play, pause, page curl etc in the xib file. Now how can I do that programmatically?


Solution

  • this should work (in viewDidLoad)

    UIBarButtonItem *barButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:systemItem target:tar action:act] autorelease];
    self.navigationItem.rightBarButton = barButtonItem;
    

    where systemItem is the UIBarButtonSystemItem type you want to use. full list of options here