Question: Tried this but only works for UIButton:

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

```

Answer: 
Set `target` and `action` of your `UIBarButtonItem`

**Swift 5 & 4**

```
button.target = self
button.action = #selector(action)

@objc func action (sender:UIButton) {
    print("action")
}

```
For a custom `UIBarButtonItem` this works.

```
let button = UIButton(type: .custom)
button.setImage(image, for: .normal)
button.addTarget(self, action: #selector(yourFunction), for: .touchUpInside)
let barButtonItem = UIBarButtonItem(customView: button)

```

You set the target and action to the button that you are adding to your `UIBarButtonItem`.