我有表格 View 单元格,其中包含堆栈 View 等。如果满足某些要求,则堆栈 View 只能位于单元格中。如果不是,则应降低单元的高度。 当我使用 .isHidden 时,高度保持不变。但我希望从该单元格中删除堆栈 View 。
这是我的代码:
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()
}
谁能告诉我该怎么做?
最佳答案
您应该使用不同的单元原型(prototype)RumCell
(不带stackview)和RumCellDetailed
(带stackview),它们都符合协议(protocol)RumCellProtocol
(其中您可以设置朗姆酒
var)
protocol RumCellProtocol {
func config(rum: Rum)
}
和这段代码:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
var cellIdentifier = "RumCellDetailed"
if (cell.rum?.clubRatingJuicy == 0) && (cell.rum?.clubRatingGasy == 0) && (cell.rum?.clubRatingSpicy == 0) && (cell.rum?.clubRatingSweet == 0) {
cellIdentifier = "RumCell"
}
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! RumCellProtocol
let currentRum: Rum
currentRum = rumList[indexPath.row]
cell.config(rum: currentRum)
return cell
}
关于ios - Swift 3 Table View - 从某些单元格中删除堆栈 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42531133/