我想使用自定義單元格創建動態單選按鈕。我試過並能夠使用故事板創建。但如何只允許一個單選按鈕選擇?動態單選按鈕uitableview自定義單元格ios
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MChangeServiceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"changeServiceCellidentifier"];
cell.serviceLabelView.text [email protected]"test";
cell.radioButton.tag=indexPath.row;
[cell.radioButton addTarget:self action:@selector(radioButtonColorChange:) forControlEvents:UIControlEventTouchUpInside];
return cell;
}
- (void)radioButtonColorChange:(id)sender
{
UIButton *button=(UIButton *) sender;
NSIndexPath *indexpath = [NSIndexPath indexPathForRow:button.tag inSection:0];
MChangeServiceTableViewCell *tappedCell = (MChangeServiceTableViewCell *)[self.listTableView cellForRowAtIndexPath:indexpath];
if ([tappedCell.radioButton.imageView.image isEqual:[UIImage imageNamed:@"radio_button_unselected.png"]])
{
[tappedCell.radioButton setImage:[UIImage imageNamed:@"radio_button_selected.png"] forState:UIControlStateNormal];
}
else
{
[tappedCell.radioButton setImage:[UIImage imageNamed:@"radio_button_unselected.png"] forState:UIControlStateNormal];
}
}
我能夠通過點擊它。但是如何改變剩餘的單選按鈕選中的狀態時,按下一個按鈕更改單選按鈕的形象?
如果你有問題,你可以上傳你與什麼不工作解釋清楚試了一下,並提供[最小,完整,可驗證的示例]( https://stackoverflow.com/help/mcve)。我建議閱讀[如何問](http://stackoverflow.com/help/how-to-ask)一個很好的問題。此外,一定要採取[旅遊](https://stackoverflow.com/tour) –