【发布时间】:2018-07-16 18:36:39
【问题描述】:
我正在使用电子商务应用程序,但在尝试设置特定行的高度时遇到问题。当我选择类别时,表格会重新加载,并且根据我选择的类别,或多或少的行会通过 api。
因此,使用此设置,当我选择特定类别时它可以工作,但是当我选择另一个类别时,它会弄乱我的行并将高度增加到另一个
let firstCellHeight:CGFloat = 265
let addBtnCellHeight:CGFloat = 60
let phoneCellHeight: CGFloat = 95
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
let cellIdentifier = self.tableCells[indexPath.row]
let height:CGFloat!
switch cellIdentifier {
case "AddAdImagesCell":
height = self.firstCellHeight
case "AddBtnCell":
height = self.addBtnCellHeight
case "ExtraFieldCell":
if indexPath.row == 4 {
height = self.phoneCellHeight
} else {
height = 44
}
default:
height = 44
}
return height
}
对于具有此代码的第 i 行的单元格:
case "ExtraFieldCell":
let currentField = self.extraFields[indexPath.row - self.firstExtraFieldIndex]
switch currentField.type {
case "select":
let cell = tableView.dequeueReusableCell(withIdentifier: "ExtraFieldSelectCell")!
if currentField.name == "area"
return cell
case "text":
let cell = tableView.dequeueReusableCell(withIdentifier: "ExtraFieldTextCell") as! FiltersTFCell
cell.label.text = "\(currentField.label):"
return cell
case "checkbox":
let cell = tableView.dequeueReusableCell(withIdentifier: "ExtraFieldCheckboxCell") as! CheckboxCell
cell.fieldLabel.text = currentField.label
return cell
default:
let cell = UITableViewCell()
return cell
}
那么如何为case "text"的行设置高度95
【问题讨论】:
-
当您选择其他类别时,您是否致电
reloadData()? -
是的。 everytime ,还有一个设置额外字段的函数
-
tableCells中的值放在哪里?这是您的实际代码吗?您的单元格出队代码将崩溃,因为它不允许在第一次使用该形式的出队函数使单元格出队时返回nil。 -
我有,但是有很多代码我不想在这里全部链接
标签: ios swift uitableview swift3