【发布时间】:2022-01-24 11:04:51
【问题描述】:
我正在使用带有标题的 UITableView。对于标题,我使用 viewForHeaderInSection。我的标题单元格中有一个标签和一个按钮。我还有一个数组来给我的 headerViewCell 的标签命名。我的数组是
let cellArray = ["Cat", "Dog", "Mouse", "Girraffe", "Zebra"]
我正在为 headerViewCell 的按钮添加一个 @objc 函数并使用按钮的标签。
这是我的代码:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerView = tableView.dequeueReusableCell(withIdentifier: "HeaderTableViewCell") as! HeaderTableViewCell
headerView.cellLabel.text = self.cellArray[section]
headerView.cellButton.tag = section
headerView.cellButton.addTarget(self, action: #selector(expandRow(sender:)), for: .touchUpInside)
return headerView
}
我的问题是我想更改所选单元格的 @objc func 中的 cellLabel。假设我点击第一个单元格,我想更改第一个单元格标签名称,但不知道该怎么做。
如果我们使用行而不是标题,这很容易,因为行有 cellForRowAt。但我无法访问该选定的标题单元格。
有人有解决办法吗?
【问题讨论】:
标签: swift xcode uitableview xcode13 uitableviewsectionheader