首先定义一个变量来记录按钮的状态
@property (assign, nonatomic) NSIndexPath *selIndex;//单选,当前选中的行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSInteger row= [indexPath row];
NSInteger oldRow = [_selIndex row];
if (row == oldRow && _selIndex) {
[cell.descriptionLabel setTitleColor:SubjectColor forState:UIControlStateNormal];
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger newRow = [indexPath row];
NSInteger oldRow = self.selIndex?[self.selIndex row]: - 1;
if (newRow != oldRow) {
MissTableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
[newCell.descriptionLabel setTitleColor:SubjectColor forState:UIControlStateNormal];
MissTableViewCell *oldCell = [tableView cellForRowAtIndexPath:indexPath];
[oldCell.descriptionLabel setTitleColor:RGB(152, 162, 177) forState:UIControlStateNormal];
self.selIndex = indexPath;
}
}