How to remove cell from static UITableView created in Storyboard

前端 未结 7 2400
野性不改
野性不改 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:45

    The first thing you can do is tag the cell from storyboard which you want to hide. Put some standard number which you can identify.

    Add this code.

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
        if (cell.tag==10) { //I have put 10 for some static cell.       
                    cell.hidden=YES;
                    return 0;         
    
        }
         cell.hidden = NO;
        return [super tableView:tableView heightForRowAtIndexPath:indexPath];
    }
    

提交回复
热议问题