NSPointerArray basics

582 views Asked by At

I'm trying to get a hang of the NSPointerArray-class, and have a very specific question regarding table view cells.

If I stored the pointer to a cell that is being pressed in a NSPointerArray, will I be able to trace it back to the original cell that was being pressed, even though that cell has been reused?

I hope you understand what I mean, but basically I'm trying to implement a snapchat-like functionality with countdown-timers when cells are being pressed.

1

There are 1 answers

0
Robotic Cat On BEST ANSWER

If you store a pointer to a UITableViewCell you will be able to find the cell that was originally pressed but this is a re-usable cell and will no longer be in the state it was when it was pressed. It will likely now hold different information.

Better would be to store the indexPath of the pressed cell so you could go back to your data model and find the original data for that pressed cell. A simple array will hold indexPath objects.

Tracking the indexPath will let you know which cells you actually pressed but the indexPath does not contain a pointer to a specific cell. Rather it just contains a record that someone pressed a cell in a section/row (e.g. An indexPath object contains info of section and row). From this info you can access the data in your model and do whatever you require.