Bhanupriya Bhanupriya - 2 months ago 22
Swift Question

how to programmatically set action for barButtonItem in swift 3?

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. Thanks in advance.

Answer

ex:-

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