必须一次又一次地标记/取消标记(假设您一次只需要选择一个)边框颜色,例如-
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if(indexPath.row==self.selectedRow){
cell.borderView.layer.borderColor = [UIColor yellowColor].CGColor;
}else {
cell.borderView.layer.borderColor = [UIColor clearColor].CGColor;
}
}
只需保存/缓存选定的索引,例如-
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//Unselected the prevoius selected Cell
YourCellClass *aPreviousSelectedCell= (YourCellClass*)[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:self.selectedRow inSection:0]];
aPreviousSelectedCell.borderView.layer.borderColor = [UIColor clearColor].CGColor;
//Selected the new one-
YourCellClass *aSelectedCell = (YourCellClass*)[tableView cellForRowAtIndexPath:indexPath];
aSelectedCell.borderView.layer.borderColor = [UIColor yellowColor].CGColor;
self.selectedRow = indexPath.row;
}