隐藏并显示tableviewcell?

时间:2018-02-06 07:55:33

标签: swift uitableview button

1.我有一个控制细胞高度的按钮 按下按钮后我想将indexPath.row == 1 height更改为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

I want to get language.identifier in tableViewCell

1 个答案:

答案 0 :(得分:0)

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

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

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

  3. 检查heightForRow func中bool的当前值并相应地设置高度。

  4. 这样的事情:

    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
    }