1. 程式人生 > >當TableView點選的時候,去除點選的陰影

當TableView點選的時候,去除點選的陰影

我們在點選UITableView的cell時,會出現陰影,如不做處理,就會一直顯示,怎麼樣讓它點選之後就消失呢?只要重寫UITableView的代理方法,就可以解決,方式如下:

-(void)tableView:(UITableView *)tableViewdidSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

//當手指離開某行時,就讓某行的選中狀態消失

   [tableView deselectRowAtIndexPath:indexPath animated:YES];

}

有兩個:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

//    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

//    [cell setSelectionStyle:UITableViewCellSelectionStyleNone]; (這種是沒有點選後的陰影效果)

    UITableViewCell *cell = [tableViewcellForRowAtIndexPath:indexPath];  

    cell.selected =NO;  (這種是點選的時候有效果,返回後效果消失)