a)点击背景会变蓝色
- (UITableViewCellAccessoryType)tableView:(UITableView*)tableViewaccessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row==currentIndex){
returnUITableViewCellAccessoryCheckmark;
}
else{
returnUITableViewCellAccessoryNone;
}
}
-(void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableViewdeselectRowAtIndexPath:indexPath animated:NO];
if(indexPath.row==currentIndex){
return;
}
NSIndexPath *oldIndexPath =[NSIndexPath indexPathForRow:currentIndex
inSection:0];
UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath];
if(newCell.accessoryType == UITableViewCellAccessoryNone) {
newCell.accessoryType =UITableViewCellAccessoryCheckmark;
newCell.textColor=[UIColor blueColor];
}
UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:oldIndexPath];
if(oldCell.accessoryType ==UITableViewCellAccessoryCheckmark){
oldCell.accessoryType = UITableViewCellAccessoryNone;
oldCell.textColor=[UIColor blackColor];
}
currentIndex=indexPath.row;
}
b)点击背景不会蓝色
- (void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if(seletedRow == [indexPath row])
return;
seletedRow = [indexPath row];
[self.tableView reloadData];
}
-(UITableViewCellAccessoryType)tableView:(UITableView*)tableViewaccessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath
{
int row = [indexPath row];
if(row == select)
returnUITableViewCellAccessoryCheckmark;
returnUITableViewCellAccessoryNone;
}