【发布时间】:2017-06-18 19:24:31
【问题描述】:
我想使用自定义单元格创建动态单选按钮。我尝试并能够使用故事板创建。但是如何只允许一个单选按钮选择?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MChangeServiceTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"changeServiceCellidentifier"];
cell.serviceLabelView.text =@"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];
}
}
我可以通过单击来更改单选按钮的图像。但是单击一个按钮时如何将剩余的单选按钮更改为未选中状态?
【问题讨论】:
-
如果您有任何问题,您可以发布您尝试过的内容,并清楚说明哪些内容不起作用,并提供Minimal, Complete, and Verifiable example。我建议阅读How to Ask 一个好问题。另外,请务必使用tour
标签: ios objective-c