UITableView tap to deselect cell

前端 未结 14 1731
野性不改
野性不改 2020-12-16 10:37

I have a UITableViewCell that is selected when tapped. During this selected state, if the user taps the cell again, I want the cell to deselect.

I can\

14条回答
  •  失恋的感觉
    2020-12-16 11:35

    When you select a cell this delegate method is triggered.

    - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
            UITableViewCell *theUITableViewCell = [tableView cellForRowAtIndexPath:path];
            if (theUITableViewCell.selected == YES){
                self.tableView deselectRowAtIndexPath:<#(NSIndexPath *)#> animated:<#(BOOL)#>
                // Do more thing
            }else{
                // By default, it is highlighted for selected state
            }
    
     }
    

    It's pseudo code.

提交回复
热议问题