How to remove cell from static UITableView created in Storyboard

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

    Depending on how your table is supposed to work, in your data source you can implement tableView:numberOfRowsInSection: to return 0 rows for the section based on your necessary logic.

    Updated for your comment:

    The section parameter will be populated by iOS when your implementation is called so all you need is a switch to handle the section that has the row you ant removed/hidden. Example below:

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
        switch(section) {
            case 0:  // first section of your table, change for your situation
                 return 0;
            default:
                 return 0;
        }
    }
    

提交回复
热议问题