首先定義一個變量來記錄按鈕的狀態
@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;
}
}