Search code examples
iosobjective-ciphoneswiftuibarbuttonitem

How to set target and action for UIBarButtonItem at runtime


Tried this but only works for UIButton:

[btn setTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];

Solution

  • Just set the UIBarButtonItem's target and action properties directly.