我有两个带有两个按钮的UIViewControllers。
如何禁用第一个类/ UIViewController中的第二个按钮?
感谢。
答案 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
}
}