【发布时间】:2015-02-19 17:37:13
【问题描述】:
我在表格视图单元格中有一个单选按钮。这是我的单选按钮
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell"];
if(cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"myCell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
radiobtn = [UIButton buttonWithType:UIButtonTypeCustom];
radiobtn.frame = CGRectMake(30, 0, 15, 14.5);
[radiobtn setImage:[UIImage imageNamed:@"unselect"] forState:UIControlStateNormal];
[radiobtn setImage:[UIImage imageNamed:@"select"] forState:UIControlStateSelected];
[radiobtn addTarget:self action:@selector(radiobtn:) forControlEvents:UIControlEventTouchUpInside];
cell.accessoryView = radiobtn;
}
cell.textLabel.text = [array objectAtIndex:indexPath.row];
return cell;
}
-(void)radiobtn:(id)sender
{
if([sender isSelected])
{
[sender setSelected:NO];
} else
[sender setSelected:YES];
} }
在上述编码中,单选按钮未更改为选中状态。请帮我编码。
【问题讨论】:
-
试试这个链接对你有用stackoverflow.com/questions/25642756/…
标签: ios objective-c uibutton radio-button radiobuttonlist