How to deselect a selected UITableView cell?

前端 未结 24 3167
一整个雨季
一整个雨季 2020-12-07 10:10

I am working on a project on which I have to preselect a particular cell.

I can preselect a cell using -willDisplayCell, but I can\'t deselect it when t

24条回答
  •  萌比男神i
    2020-12-07 10:30

    Can you try this?

    - (void)tableView:(UITableView *)tableView 
      didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
        AppDelegate_iPad *appDelegte = 
        (AppDelegate_iPad *)[[UIApplication sharedApplication] delegate];
        NSIndexPath *indexpath1 = appDelegte.indexPathDelegate;
        appDelegte.indexPathDelegate = indexPath;
    
        UITableViewCell *prevSelectedCell = [tableView cellForRowAtIndexPath: indexpath1];
        if([prevSelectedCell isSelected]){
           [prevSelectedCell setSelected:NO];
        }
    }
    

    It worked for me.

提交回复
热议问题