ios - 如何禁用另一个类的按钮?
问题描述
我有两个带有两个按钮的 UIViewController。
如何从第一个类/UIViewController 中禁用第二个按钮?
谢谢。
解决方案
类视图控制器 1
class ViewController: UIViewController {
@IBAction func btn1(_ sender: UIButton) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "Disable"), object: nil)
}
}
类视图控制器 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
}
}
推荐阅读
- c# - 从循环中调用时,C# async await 方法是否并行运行?
- aws-appsync - Exception in generateClasses when building AppSync project in Debug but not Release
- python - python type.cast 在 Python 中有什么作用?
- wordpress - 带有叶子类别的 Wordpress 存档永久链接
- javascript - One Click Deploy Solution for my webapp
- string - string[] 包括 EFCore2.1
- r - R中的自定义Keras损失函数,带有case_when函数
- c# - 试图找到第 10001 个素数,c#
- c# - 'Ref' 和 'Out' 参数的内存分配,有什么区别吗?
- mysql - Why type data "long blob" in mysql read as "int8" in data explorer MATLAB?