2017912205527dama.png
自定义选中样式很简单,直接在下面两个方法中添加就行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
MLPayStyleCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selectButton.selected = YES;
//传值
if (cell.model)
{
cell.model = _payStyleDataArr[indexPath.row];
self.sendPayStyleValueBlock(cell.model.termValue);
}
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
MLPayStyleCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.selectButton.selected = NO;
}
设置默认选中
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MLPayStyleCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MLPayStyleCell class]) forIndexPath:indexPath];
cell.model = _payStyleDataArr[indexPath.row];
if (indexPath.row == 0)
{
cell.selectButton.selected = YES;
// cell.selected = YES;
//设置cell的选中状态,然后选中其他的cell时,可以调用didDeselectRowAtIndexPath:方法,取消cell上按钮的选中状态
[self selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
}
return cell;
}
如果利用cell.selected = YES
来设置选中按钮,会出现下面的情况
2017912205601dama.png
网友评论