gpt4 book ai didi

ios - 将当前的 UITableViewCell 滑动传递给父 UITableView

转载 作者:行者123 更新时间:2023-11-28 06:18:08 25 4
gpt4 key购买 nike

我有一个自定义的 UITableViewCell,它具有向右滑动的功能。滑动手势是基于 x 轴的平移,所以,当 x 的平移超过 40 点时,我想触发一个 segue。

我认为这是使用委托(delegate)来传递有关当前 X 值的数据的完美场所。所以,我创建了一个带有函数 didSwipeCell()protocol,但我不确定如何将当前 x 值传递给 UITableView

请让我知道如何操作,如果您需要任何额外信息,请在评论中告诉我,而不是投反对票。

最佳答案

添加x值作为didSwipeCell()方法的参数

protocol TableViewCellDelegate {
func didSwipeCell(on xValue: Float)
}

将委托(delegate)实例添加到您的单元格

class TableViewCell: UITableViewCell {
weak var delegate: TableViewCellDelegate?
}

然后,当用户滑动给定 xValue 的单元格时调用该方法

delegate?.didSwipeCell(on: xValue)

在您的 UITableView 中实现 TableViewCellDelegate 方法。

 class TableView: UITableView, TableViewCellDelegate {
func didSwipeCell(on xValue: Float) {
//here you can get the xValue
}

并且,不要忘记在您的 cellForRowAtIndexPath 方法中设置 TableViewCell 的委托(delegate)

cell.delegate = self

关于ios - 将当前的 UITableViewCell 滑动传递给父 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44503778/

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