2016-06-21 83 views
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)") 
} 

上面的代码会引发转换错误。

+0

你可以使用一个'SSRadioButtonsController'数组。 – Code

+0

这样的@Code? 'var radioButtonController:[SSRadioButtonsController] = []' – user2640921

+0

是的。 ////////// – Code

回答

1

我不认为有什么办法可以做你想做的事情。

您可以将所有单选按钮放入一个数组中,然后使用数组索引在枚举时找到想要的按钮。