1
我有类似的按钮类型,他们唯一的区别是整数附加在名称的末尾。追加字符串与视图名称
代码片段:
radioButtonController1 = SSRadioButtonsController(buttons: radioBtn1,radiobtn2)
radioButtonController1!.delegate = self
radioButtonController1!.shouldLetDeSelect = false
radioButtonController2 = SSRadioButtonsController(buttons: radioBtn3,radioBtn4)
radioButtonController2!.delegate = self
radioButtonController2!.shouldLetDeSelect = false
radioButtonController3 = SSRadioButtonsController(buttons: radioBtn5,radioBtn6,radioBtn7)
radioButtonController3!.delegate = self
radioButtonController3!.shouldLetDeSelect = false
radioButtonController4 = SSRadioButtonsController(buttons: radioBtn8,radioBtn9)
radioButtonController4!.delegate = self
radioButtonController4!.shouldLetDeSelect = false
现在,我想这样做在一个循环,以减少代码。有什么办法,我可以循环做?就像创建一个变量并在末尾添加一个整数,如下所示:
for index in 1...11 {
radioButtonController = radioButtonController.append("\(index)")
}
上面的代码会引发转换错误。
你可以使用一个'SSRadioButtonsController'数组。 – Code
这样的@Code? 'var radioButtonController:[SSRadioButtonsController] = []' – user2640921
是的。 ////////// – Code