gpt4 book ai didi

ios - 快速确定某一行是否从 View 中消失

转载 作者:搜寻专家 更新时间:2023-11-01 06:38:02 26 4
gpt4 key购买 nike

我一直在寻找解决方案,但直到现在都没有结果。我想要做的是确定某个单元格是否从屏幕上消失了。

这是我一直在尝试的代码:

func tableView(tableView: UITableView, didEndDisplayingCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {

let indexPathWatchCell = NSIndexPath(forRow: 4, inSection: 0)

if ((tableView.indexPathsForVisibleRows?.contains(indexPathWatchCell)) == nil){
NSLog("it disappeared!!")
}
}

不幸的是它不起作用,有什么想法吗?

编辑:

为了清楚起见,我想要完成的是在单元格消失在 View 中时将单元格的大小设置为 CGFLOAT(44)

最佳答案

contains 方法返回 bool 值,如果对象包含其他明智的返回 false,所以你需要检查它而不是 nil 所以像这样改变你的代码。

if (tableView.indexPathsForVisibleRows?.contains(indexPathWatchCell)){
NSLog("it not disappeared!!")
}
else {
NSLog("it's disappeared!!")
}

或者,如果您只是想知道“消失”,您可以使用 !(不是)和 if

if (!tableView.indexPathsForVisibleRows?.contains(indexPathWatchCell)){
NSLog("it disappeared!!")
}

关于ios - 快速确定某一行是否从 View 中消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39140714/

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