swift determine if a certain row disappear from view

点点圈 提交于 2019-12-11 05:11:29

问题


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?

EDIT:

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


回答1:


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


来源:https://stackoverflow.com/questions/39140714/swift-determine-if-a-certain-row-disappear-from-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!