How to remove cell from static UITableView created in Storyboard

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

    Use index path to identify the cell in tableview height delegate and return 0

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    
            if someCondition {
    
                if indexPath.row == 1 || indexPath.row == 2 || indexPath.row == 3 {
                    return 0 
                }
    
            }else{
    
                if indexPath.row == 4 {
                    return 0 
                }
    
            }
    
    
        return super.tableView(tableView, heightForRowAt: indexPath)
    }
    

提交回复
热议问题