Hide cells in a UITableView with static cells - and no autolayout crash

前端 未结 9 1760
庸人自扰
庸人自扰 2021-01-01 16:01

I have a table view form created using Static Cells in IB/Storyboard. However, I need to hide some of the cells at runtime depending on certain conditions.

I have fo

9条回答
  •  情话喂你
    2021-01-01 16:36

    Hide the cells on the storyboard and set the height to 0:

    override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
        let cell: UITableViewCell = super.tableView(tableView, cellForRowAtIndexPath:indexPath)
        return cell.hidden ? 0 : super.tableView(tableView, heightForRowAtIndexPath:indexPath)
        }
    }
    

提交回复
热议问题