匿名 2017-08-14 22:11
点击UISwitch后,怎么去改变在同一个Cell中的另一个UISwitch的状态?
回复:1 查看:6650
像下面的图片所示,一个Cell中的其中一个
UISwitch
打开后,另外两个关上。
Swift 2018-02-24 15:54
在Cell对应的类(UITableViewCell子类)中增加3个开关的@IBOutlet绑定,其中一个开关增加@IBAction事件,在事件中判断来改变其他2个开关的状态。
@IBOutlet weak var switch1: UISwitch!
@IBOutlet weak var switch2: UISwitch!
@IBOutlet weak var switch3: UISwitch!
@IBAction func switch1Change(_ sender: UISwitch) {
if switch1.isOn {
switch2.setOn(false, animated: true)
switch3.setOn(false, animated: true)
} else {
switch2.setOn(true, animated: true)
switch3.setOn(true, animated: true)
}
}