snehal B.
snehal B.

Reputation: 29

Get title of a navigation bar button item in swift?

I am not able to get navigation bar button item, when I created action outlet.Here is my code

@IBAction func rightBarButtonItemDidTap(_ sender: Any) {
    print(sender.title)
}

but title is not available.

Upvotes: 1

Views: 191

Answers (1)

Vinod
Vinod

Reputation: 80

Try this

    @IBAction func rightBarButtonItemDidTap(_ sender: Any) {
       let barButton = sender as? UIBarButtonItem
       if let title = barButton?.title {
         print(title)
       }
     }

Upvotes: 2

Related Questions