我刚刚在自定义单元格上添加了一个按钮
“查看评论”按钮,我想做的是通过点击此按钮来展开或折叠单元格,我还想在单元格展开时显示其他标签。现在为了知道我要点击哪个单元格,我在 cellForRowAt 中创建了一个标签
cell.reviewButton.tag = indexPath.row
cell.reviewButton.addTarget(self, action: #selector(CourseClass2.ReviewButtonTap(_:)), for: .touchUpInside)
和 IBAction
@IBAction func ReviewButtonTap(_ sender: UIButton) {
let index2 = IndexPath(row: sender.tag, section: 0)
}
但我不知道如何展开或折叠,特别是我不知道如何在展开时显示单元格中的其他元素,我已经环顾网络,但没有找到有用的教程,我'我是初学者,有人可以解释我该怎么做吗?
最佳答案
我不知道最好的方法是什么。但我将创建标题
而不是单元格
,当按下按钮
“查看评论”时,我将添加
并删除
与该 header 相关的单元格。
查看本教程:https://newfivefour.com/swift-ios-expanding-uitableview-sections.html .
在 numberOfRowsInSection
中,您可以决定该 header 的展开/折叠操作。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if hidden[section] {
return 0
} else {
return 1
}
}
关于ios - 使用按钮展开/折叠 tableView 单元格,并在单元格展开时显示 View 中的其他元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48213355/