首先定义一个变量来记录按钮的状态

@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;

    }

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐