How to programmatically set action for barButtonItem in swift 3?

Bhanupriya picture Bhanupriya · Sep 29, 2016 · Viewed 83.4k times · Source

Here is what I used previously,

var barButtonItem = UIBarButtonItem(image: backImgs, style: UIBarButtonItemStyle.plain, target: self, action: Selector("menuButtonTapped:"))

But there is some syntax changes for Swift 3.

Answer

Tony Vincent picture Tony Vincent · Sep 29, 2016

ex:-

navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Add", style: .plain, target: self, action: #selector(addTapped))