【问题标题】:hide and show tableviewcell?隐藏和显示tableviewcell?
【发布时间】:2018-02-06 07:55:33
【问题描述】:

1.我有一个按钮来控制单元格的高度 按下按钮后,我想将 indexPath.row == 1 高度更改为 44 再次按到高度为 0

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.section == 0 && indexPath.row == 1 {
        return 0
    }
    return 44
}

2.我在 tableViewCell 中有一个按钮 按下按钮可以改变父视图的约束

我想在tableViewCell中获取language.identifier

【问题讨论】:

  • 1.总计,你有多少行? 2. 这意味着?改变父母视图的约束??
  • 1.只有两行 2. 我想在 tableViewCell 中获取 language.identifier,左图 37-38
  • 可以,给你截图看看,设计如何?
  • 屏幕应该是怎样的?

标签: swift uitableview button


【解决方案1】:

关于你的第一个问题,试试这个:

  1. 创建一个Bool 变量并将其设置为类的顶部作为全局变量。

  2. 在按钮的操作中,更改变量的当前值,然后应用tableView.reloadData()

  3. 检查heightForRow函数中布尔值的当前值,并相应地设置高度。

类似这样的:

var isHeightZero = true

@IBAction func toggleHeight(_ sender: UIButton) {
    isHeightZero = !isHeightZero
    tableView.reloadData()
} 

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.section == 0 && indexPath.row == 1 {
        if isHeightZero {
            return 0
        } else {
            return 44
        }
    }
    return 44
}

【讨论】:

  • 谢谢。它正在工作!
  • @user9320514 很高兴。伙伴。如果您不介意,请将我的答案标记为正确答案;)。
猜你喜欢
  • 2018-01-21
  • 2017-09-03
  • 2014-07-31
  • 2017-02-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多