ios - 使用按钮展开/折叠 tableView 单元格,并在单元格展开时显示 View 中的其他元素

标签 ios swift uitableview swift4

我刚刚在自定义单元格上添加了一个按钮

enter image description here

“查看评论”按钮,我想做的是通过点击此按钮来展开或折叠单元格,我还想在单元格展开时显示其他标签。现在为了知道我要点击哪个单元格,我在 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/

相关文章:

ios - __NSCFConstantString objectAtIndex :]: unrecognized selector sent to instance

ios - 搜索栏 Controller iOS 11 问题 - 搜索栏和范围按钮重叠

ios - Objective-C 中的链表问题

ios - Scene Kit 联系 catagoryBitMasks 总是返回 1

swift - swift 一个 View 上的两个表

ios - 具有相同子值的 firebase 中的分页

swift - 如何检测快速移动的分数节点

swift - 在 Xcode 中创建自定义 View 列表

ios - 我知道如何仅在顶部禁用 uitableview 的弹跳 - 但我如何才能仅在底部执行此操作?

iphone - iOS - 如何处理自定义表格单元格中的方向变化