Can you animate a height change on a UITableViewCell when selected?

前端 未结 21 1054
天涯浪人
天涯浪人 2020-11-22 04:41

I\'m using a UITableView in my iPhone app, and I have a list of people that belong to a group. I would like it so that when the user clicks on a particular pers

21条回答
  •  梦毁少年i
    2020-11-22 04:58

    I used @Joy's awesome answer, and it worked perfectly with ios 8.4 and XCode 7.1.1.

    In case you are looking to make your cell toggle-able, I changed the -tableViewDidSelect to the following:

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    //This is the bit I changed, so that if tapped once on the cell, 
    //cell is expanded. If tapped again on the same cell, 
    //cell is collapsed. 
        if (self.currentSelection==indexPath.row) {
            self.currentSelection = -1;
        }else{
            self.currentSelection = indexPath.row;
        }
            // animate
            [tableView beginUpdates];
            [tableView endUpdates];
    
    }
    

    I hope any of this helped you.

提交回复
热议问题