如何禁用其他课程的按钮?

时间:2018-06-02 11:20:08

标签: ios swift class button uiviewcontroller

我有两个带有两个按钮的UIViewControllers。

如何禁用第一个类/ UIViewController中的第二个按钮?

感谢。

1 个答案:

答案 0 :(得分:1)

Class ViewController 1

class ViewController: UIViewController {
@IBAction func btn1(_ sender: UIButton) {
    NotificationCenter.default.post(name: NSNotification.Name(rawValue: "Disable"), object: nil)
}

}

Class ViewController 2

class ViewController2: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()
    NotificationCenter.default.addObserver(self, selector: #selector(ViewController2.disableBtn), name: NSNotification.Name(rawValue: "Disable"), object: nil)
}
@IBOutlet weak var btn2: UIButton!
@objc func disableBtn() {
    btn2.isEnabled = false
}

}