我有表视图单元格,其中包含堆栈视图 . 如果某些要求为真,则堆栈视图应仅位于单元格中 . 如果不是,则应减小单元的高度 . 当我使用.isHidden时,高度保持不变 . 但我希望从该单元格中删除堆栈视图 .
这是我的代码:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "RumCell", for: indexPath) as! RumCell
let currentRum: Rum
currentRum = rumList[indexPath.row]
cell.rum = currentRum
if (cell.rum?.clubRatingJuicy == 0) && (cell.rum?.clubRatingGasy == 0) && (cell.rum?.clubRatingSpicy == 0) && (cell.rum?.clubRatingSweet == 0) {
cell.frame.size.height -= 76
}
return cell
}
如您所见,我试图降低单元格高度,但这不起作用 . 我也试过这个,这不起作用:
if (cell.rum?.clubRatingJuicy == 0) && (cell.rum?.clubRatingGasy == 0) && (cell.rum?.clubRatingSpicy == 0) && (cell.rum?.clubRatingSweet == 0) {
cell.tastStack.removeFromSuperview()
}
谁能告诉我怎么做?
3 回答
尝试动态高度的代码,并在tableView单元格中给出没有修复高度的约束
你应该使用不同的单元原型
RumCell
(没有stackview)和RumCellDetailed
(带有stackview),它们都符合协议RumCellProtocol
(你可以设置rum
var)而这段代码:
你不应该设置单元格框架 . 这不是TableView的工作方式 . 如果单元格高度是动态的,则@Theorist是正确的 . 如果没有,您可以实施