How to remove cell from static UITableView created in Storyboard

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

    You can't really deal with this in the datasource since with static tables you don't even implement the datasource methods. The height is the way to go.

    Try this:

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        if (cell == cell15 && cell15ShouldBeHidden) //BOOL saying cell should be hidden
            return 0.0;
        else
            return [super tableView:tableView heightForRowAtIndexPath:indexPath]; 
    } 
    

    Update

    It appears that, under autolayout, this may not be the best solution. There is an alternative answer here which may help.

提交回复
热议问题