具體的步驟是三個,第一步設定cell選擇狀態下的背景view
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.selectedBackgroundView= [[UIViewalloc]initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor= [UIColororangeColor];
此時記得不要設置點擊類型為none
第二步在didSelectRowAtIndexPath的選擇方法里面執行下面代碼,這句代碼是用來延遲執行的,因為我的需求是點擊后變回原樣
[selfperformSelector:@selector(cancleSelect)withObject:nilafterDelay:0.1f];
它的意思是將會在你執行完點擊cell的方法后,0.1秒后執行下面一個方法
- (void)cancleSelect
{
[self.tableViewdeselectRowAtIndexPath:[self.tableViewindexPathForSelectedRow]animated:YES];
}
這樣就可以達到點擊cell變色,放開后恢復的效果了