Nick Forge
Nick Forge

Reputation: 21464

Is there an easy way to observe the visible cells in a UITableView?

I need to keep track of the visible cells in a UITableView, since certain events need to occur when cells that represent specific pieces of data become visible. UITableView doesn't seem to be KVO compliant for -indexPathsForVisibleRows or -visibleCells, and there's no UITableViewDelegate method that gives a hook for being notified that the visible cells have changed.

Is there any way of doing this, short of manually keeping track of my own array, and adding/removing objects every time I insert/remove a row, reload the table, or methods like -tableView:cellForRowAtIndexPath: are called?

Upvotes: 9

Views: 2454

Answers (3)

horseshoe7
horseshoe7

Reputation: 2817

If you're not doing too many exotic things with the table itself, like re-arranging and deleting/inserting rows, you could use the scrollviewDidScroll: method, and the other scrollview delegate methods that are sent by a tableview.

in that method you can call visibleCells and go from there.

Upvotes: 0

Nick Forge
Nick Forge

Reputation: 21464

Without hacking/subclassing UITableView or UITableViewCell, the answer appears to be no.

Upvotes: 1

Swapnil Luktuke
Swapnil Luktuke

Reputation: 10475

How about UITableViewDelegate method:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

Upvotes: 6

Related Questions