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