xxxxtableview.separatorStyle=UITableViewCellSelectionStyleNone;
不然cell被重用后,会被还原为默认选中效果
2、在
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath中设置
cell.selectedBackgroundView=nil;
这步非常关键不然,之后后出现两个被选中的cell,
3在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{中自定义选中效果,以及其他其他需要
例如:
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
UIImageView *bgView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"selected_bg"]];
bgView.frame=CGRectMake(10, 0, kDeviceWidth-100, cell.frame.size.height);
bgView.contentMode=UIViewContentModeScaleAspectFit;
cell.selectedBackgroundView=bgView;
4、在
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath同时也设置
UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
cell.selectedBackgroundView=nil;
这样就可以啦,