swift确定某一行是否从视图中消失
我一直在四处寻找解决方案,但直到现在它还没有结果。 我想要做的是确定某个单元格是否从屏幕上消失。
这是我一直在尝试的代码:
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!!") } }
不幸的是它没有用,有什么想法吗?
编辑:
为清楚起见,我想要完成的是在视图中消失时将单元格的大小设置为CGFLOAT(44)
contains
方法返回布尔值如果对象包含其他明智的返回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!!") }