How to remove cell from static UITableView created in Storyboard

前端 未结 7 2369
野性不改
野性不改 2021-02-14 08:11

This should be easy, but I\'m having trouble.

I have a static UITableView with a cell that I would like to remove programmatically if it\'s not needed.

I have a

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-14 08:50

    You can use tableView:willDisplayCell and tableView:heightForRowAtIndexPath with the cell identifier to show/hide static tableview cells, but yo must implement heightForRowAtIndexPath referring to super, not to self. These two methods work fine for me:

    (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
    {
    if ([cell.reuseIdentifier.description isEqualToString:@"cellCelda1"]) {
        [cell setHidden:YES];
        }
    }
    

    and

    (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
        if ([cell.reuseIdentifier.description isEqualToString:@"cellCelda1"]) {
            return 0;
    }
        return cell.frame.size.height;
    }
    

提交回复
热议问题