检查是否选择了 UITableViewCell,并且单元格离开了屏幕

Check if a UITableViewCell is selected, and the cell went off screen

我有一个 dequeueReusableCells 的自定义 UITableViewCell。我有一个名为 selectedRow 的整数,它在 didSelectRowAtIndexPath 的方法中获取选定的行号。然后我将 selectedRow 传递给一个名为 rowNumber 的整数,它位于我的 customCell 的 class 中。

customCell.m中,我有方法prepareForReuse。在那里我制作了 rowNumber.

的 NSLog

我想做的是:如果选择了一行并且该行离开了屏幕,则执行一些代码。我可能不得不使用 prepareForReuse,但我不知道在其中做什么。

我知道这有点复杂,但如果您有任何问题,我很乐意回答

您可以在 UITableViewDelegate 中使用 - (void)tableView:tableView didEndDisplayingCell:cell forRowAtIndexPath:indexPath; 来了解哪个单元格被滚出屏幕。

但是,此方法仅 iOS6+。

你把事情复杂化了。您不必在自定义单元格中执行 prepareForReuse。

看看这个。 http://www.icodeblog.com/2009/05/24/custom-uitableviewcell-using-interface-builder/

故事板非常相似。

其实你不需要直接调用prepareForReuse因为它会被自动调用:

this method is invoked just before the object is returned from the UITableView method dequeueReusableCellWithIdentifier:.

并且由于您不知道在其中做什么,请注意:

For performance reasons, you should only reset attributes of the cell that are not related to content, for example, alpha, editing, and selection state

UITableViewCell Class Reference