How to set target and action for UIBarButtonItem at runtime

Sharief picture Sharief · Feb 25, 2010 · Viewed 89.5k times · Source

Tried this but only works for UIButton:

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

Answer

Ole Begemann picture Ole Begemann · Feb 25, 2010

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