我正在尝试获取开关的值并将其传递给 View Controller 中的对象。
下面是我的 View Controller 的代码。我创建了标签、开关 socket 和开关操作。
@IBOutlet weak var firstTimeConducting: UILabel!
@IBOutlet weak var firstTime_Conduct: UISwitch!
@IBAction func firstTimeConductSwitchTap(_ sender: Any) {
firstTimeConductTapped()
}
override func viewDidLoad() {
super.viewDidLoad()
firstTimeConductTapped()
}
func firstTimeConductTapped() {
if firstTime_Conduct.isOn {
value = "Yes"
} else {
value = "No"
}
}
我已经对其进行了调试,当我单击模拟器中从关闭到开启状态的开关时,它进入并获取值为“yes”。
然后返回函数firstTimeConductSwitchTap()
后,它崩溃并显示以下错误
"Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[app.RequestFormViewController first_TimeConduct:]: unrecognized selector sent to instance 0x7fb900421fc0'
我只是检索“value
”变量的值并将其传递给要显示的对象。
您能否建议我是否遵循了正确的程序以及为什么会出现此错误?
最佳答案
错误非常明显:
在 Interface Builder 中,与选择器 first_TimeConduct
存在死连接。您很可能重命名了操作方法。
使用 ⇧⌘F 搜索 first_TimeConduct
并删除连接。
关于swift - 如何检索 switch 的值并将其传递给 Object?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53592230/