-3

I have a UIBarButton in a Navigation Bar (the VC is embedded within a Navigation Controller). In IB I set the button with an Identifier:

Bar Button in Navigation Bar Attributes Inspector

How do I set this Attribute from code?

Ohad Regev
  • 5,641
  • 12
  • 60
  • 84

1 Answers1

4

You should be able to set it like

UIBarButtonItem *trashButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:nil];

Check out the Apple Documentation for this here

Unfortunately, Apple only allow you to set this when you initialize the UIBarButtonItem there isn't a property to set this.

Popeye
  • 11,839
  • 9
  • 58
  • 91
  • So it means I have to create a new button every time? I read the documentation and it seemed weird there's no Property or a setIdentifier:ForState method... – Ohad Regev Jan 13 '14 at 12:25
  • 1
    Yeah, unfortunately there isn't a property you can just set you have to do it when you `alloc init`. Annoying but that's just the way Apple like - annoying. – Popeye Jan 13 '14 at 12:27