//无色 cell.selectionStyle = UITableViewCellSelectionStyleNone; //蓝色 cell.selectionStyle = UITableViewCellSelectionStyleBlue; //灰色 cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.selectedBackgroundView = [UIView new];
cell.selectedBackgroundView.backgroundColor = [UIColor xxxxxx];
cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellart.png"]] autorelease]; 还有字体颜色 cell.textLabel.highlightedTextColor = [UIColor xxxcolor]; [cell.textLabel setTextColor:
//设置点击没有颜色
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[theTableView setSeparatorColor:[UIColor xxxx ]];
首先我有一个UITableViewController,其中每一个UITableViewCell点击后都会push另外一个ViewController,每次点击Cell的时候,Cell都会被选中,当从push的ViewController返回的时候选中的Cell便会自动取消选中。后来因为某些缘由我把这个UITableViewController改为了UIViewController,以后就产生了一个问题:每次返回到TableView的时候,以前选中的Cell不能自动取消选中,通过查找得知:字体
UITableViewController有一个clearsSelectionOnViewWillAppear的property,spa
而当把UITableViewController修改为UIViewController后,这个属性天然就不存在了,所以咱们必须手动添加取消选中的功能,方法很简单,在viewWillAppear方法中加入:code
[self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ ………… //消除cell选择痕迹 [self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f]; } - (void)deselect{ [self.tableview deselectRowAtIndexPath:[self.tableview indexPathForSelectedRow] animated:YES]; }