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