Anthony Shahine
Anthony Shahine

Reputation: 2487

Swift 2 - iOS: disable a bar button

In the Code below, i created 2 right bar buttons using swift 2.

At this moment, i want to make something like that:

accountButton.disable = false

But that is not possible.

What is the best solution to disable this bar button ?

let accountImage   = UIImage(named: "account")!
let settingImage   = UIImage(named: "setting")!
let accountButton  = UIBarButtonItem(image: accountImage,  style: .Plain , target: self, action: "didTapEditButton:")

let settingButton  = UIBarButtonItem(image: settingImage,  style: .Plain, target: self, action: "didTapSearchButton:")

navigationItem.rightBarButtonItems = [accountButton , settingButton]

Upvotes: 3

Views: 2153

Answers (2)

pedrouan
pedrouan

Reputation: 12910

Try:

Swift 2

accountButton.enabled = false

Swift 3

accountButton.isEnabled = false

Upvotes: 4

Benbobo
Benbobo

Reputation: 121

Use UIBarButtonItem's property enabled instead of disable

Upvotes: 0

Related Questions