Led Led - 10 months ago 52
Swift Question

swift determine if a certain row disappear from view

I've have been sniffing around to find the solution but up until now its fruitless. What I want to do is to determine if a certain cell disappeared from screen.

Here's the code i have been trying:

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!!")

Unfortunately its not working, any ideas?


for clarity, what I want to accomplish is set the size of the cell to CGFLOAT(44) when it disappeared in view


contains method return Boolean value if the object contains other wise return false, so you need to check for that not for nil so change your code like this.

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

Or if you just want to know for "disappeared" than you can use !(not) with if

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