问题描述
我只是 Swift 开发的初学者。当用户选择其他按钮时,我不知道如何删除 .isSelected
解决方法
也许这对你有用:
如果您有多个按钮并且每个按钮都有不同的操作,您可以遵循以下级别:
1- 在按钮的属性检查器中选择一个标签,例如按钮 1 标签是 1
2- 在代码动作中一个按钮并为每个 Botton 连接
3- 您可以使用此代码访问每个按钮:
@IBAction func Buttons(_ sender: UIButton) {
if sender.tag == 1 {
// do for your button that tag is eaual 1
}
if sender.tag == 2 {
// do for your button that tag is eaual 2
}
if sender.tag == 3 {
// do for your button that tag is eaual 3
}
}
,
我会创建一组按钮
(str+i)
然后为所有按钮分配相同的功能
&str[i]
当用户点击按钮时,你可以对点击的按钮和其他按钮做任何你想做的事情
@IBOutlet var buttonsArray: [UIButton]!