【问题标题】:How can I disable a button from another class? [closed]如何禁用另一个类的按钮? [关闭]
【发布时间】:2018-11-12 08:39:26
【问题描述】:

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

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

谢谢。

【问题讨论】:

标签: ios swift class button uiviewcontroller


【解决方案1】:

类 ViewController 1

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

}

类 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
}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    • 2020-02-20
    • 2019-12-29
    • 2019-01-14
    相关资源
    最近更新 更多