gpt4 book ai didi

ios - 如何对静态单元格进行编程以从 Storyboard中获取高度,同时对其他单元格进行编程以从代码中获取高度

转载 作者:行者123 更新时间:2023-11-28 08:18:20 25 4
gpt4 key购买 nike

我有一个 uitableview Controller ,其中包含两个部分的静态单元格。我已经使用 Storyboard调整了第 0 节中单元格 0 和 1 的高度。但是,在切换 UIswitch 并在第 1 部分中点击单元格后,我使用代码扩展了日期选择器。

我的问题是代码覆盖了第 0 节中的单元格 0 和 1。如何强制这些单元格从 Storyboard 中获取它们的高度?如果那不可能,我将如何对它们的高度进行编码,以便单元格扩展代码不会覆盖它?

注意:我是新手,并不完全理解我用来进行扩展的代码,所以如果我需要更改它,请告诉我。代码粘贴在下面。

 var pickerVisible = false

// MARK: - COLLAPSABLE CELL

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 1 && indexPath.row == 2 {
pickerVisible = !pickerVisible
tableView.reloadData()
}
tableView.deselectRow(at: indexPath, animated: true)
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 1 && indexPath.row == 2 && toggle.isOn == false {
return 0.0
}
if indexPath.section == 1 && indexPath.row == 3 {
if toggle.isOn == false || pickerVisible == false {
return 0.0
}
return 165.0
}
return 44.0
}

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 44.0
}

最佳答案

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.section == 0 {
// set height for rows in section 0
} else if indexPath.section == 1 {
// set height for rows in section 1
} else {
// default height for your tableview cell
return 44.0
}
}
  • 我如何强制这些单元格从 Storyboard 中获取它们的高度?

-> 我认为你并不真的需要这个。

  • 我应该如何对它们的高度进行编码,以便单元格扩展代码不会覆盖它?

-> 很容易做你想做的事(上面的示例代码)

关于ios - 如何对静态单元格进行编程以从 Storyboard中获取高度,同时对其他单元格进行编程以从代码中获取高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41947807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com