我刚在自定义单元格上添加了一个按钮
按钮“查看评论”,我想要做的是通过点击此按钮展开或折叠单元格,我还想在单元格展开时显示其他标签。现在要知道我要点击哪个单元格,我在我的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)
}
但我不知道我怎么能扩展或崩溃,特别是我不知道如何在细胞扩展时显示细胞中的其他元素,我已经环顾网络,但我没有找到有用的教程,我一个初学者可以有人解释我该怎么办?
答案 0 :(得分:0)
我不知道这样做的最佳方法是什么。但我会创建headers
而不是cells
,当button
“查看评论”时,我会add
和remove
一个小组尊重报头中。
查看本教程:https://newfivefour.com/swift-ios-expanding-uitableview-sections.html。
在numberOfRowsInSection
中,您可以决定该标题的展开/展开操作方面。
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if hidden[section] {
return 0
} else {
return 1
}
}