gpt4 book ai didi

ios - 在 Storyboard中设计点击展开单元格

转载 作者:行者123 更新时间:2023-11-28 05:33:38 25 4
gpt4 key购买 nike

我在我的应用程序中添加了一项功能,允许用户添加注释,这些注释将在表格 View 单元格被点击时显示在它们展开以显示更多内容时。

我的问题是 - 如何布局单元格展开时要显示的内容?我已经尝试将 textView 添加到原型(prototype)单元格,但我只是让 textView 重叠在 TableView 中的其他单元格上,而不是在被点击之前被隐藏。

这是我在点击单元格时的代码:

var selectedRowIndex: NSIndexPath = NSIndexPath(forRow: -1, inSection: 0)

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedRowIndex = indexPath
tableView.beginUpdates()
tableView.endUpdates()
}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.row == selectedRowIndex.row {
if cellTapped == false {
cellTapped = true
return 141
} else {
cellTapped = false
return 70
}
}
return 70
}

最佳答案

您需要将单元格的 clipToBounds 属性设置为 YES(或在 IB 中为单元格选中“剪辑 subview ”复选框),这样它的所有 subview 都不会显示在单元格的边界之外。 TextView 应该对 contentView 的侧面有约束以及高度约束。它也应该对它上面的东西有一个约束,并且那个 View 应该对 contentView 的顶部有一个约束。约束应该看起来像这样,

enter image description here

关于ios - 在 Storyboard中设计点击展开单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26320643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com