The task seemed relatively simple, I wanted an if statement to determine if a check box is checked or not apparently check boxes but am at a loss
任务似乎相对简单,我想要一个if语句来确定复选框是否被选中或者显然没有复选框但是我不知所措
I've tried
if checkbox.state == everythign i can think of but it always errors either EXC_BAD_INSTRUCTION or using wrong cant convert variable type to other variable type
如果checkbox.state == everythign我可以想到但它总是错误EXC_BAD_INSTRUCTION或使用错误的cant转换变量类型到其他变量类型
2 个解决方案
#1
14
Xcode 9 • Swift 4
Xcode 9•Swift 4
You can switch the checkbox state property to check if it is on or off as follow:
您可以切换复选框状态属性以检查它是否打开或关闭,如下所示:
switch sender.state {
case .on:
print("on")
case .off:
print("off")
case .mixed:
print("mixed")
default: break
}
#2
2
i did this on my project and it worked well
我在我的项目上做到了这一点并且效果很好
if sender.state == .on{
casa_ospiti_text.stringValue = "CASA"
}
else{
casa_ospiti_text.stringValue = "OSPITI"
}
where it changes the value of a textfield (casa_ospiti_text) with constants strings.
它用常量字符串改变textfield(casa_ospiti_text)的值。
#1
14
Xcode 9 • Swift 4
Xcode 9•Swift 4
You can switch the checkbox state property to check if it is on or off as follow:
您可以切换复选框状态属性以检查它是否打开或关闭,如下所示:
switch sender.state {
case .on:
print("on")
case .off:
print("off")
case .mixed:
print("mixed")
default: break
}
#2
2
i did this on my project and it worked well
我在我的项目上做到了这一点并且效果很好
if sender.state == .on{
casa_ospiti_text.stringValue = "CASA"
}
else{
casa_ospiti_text.stringValue = "OSPITI"
}
where it changes the value of a textfield (casa_ospiti_text) with constants strings.
它用常量字符串改变textfield(casa_ospiti_text)的值。