I have a table where there will often be two cells with the same title. I'm zooming in on a map whenever a cell in the table is clicked, so using the title as a unique identifier is out of the question. I already have a unique identifier, but I need to find a way to store it in a UITableViewCell object.
I have been considering two options, both of which are poor, IMO.
1) store the unique ID as the text inside the text of the detailTextLabel property.
2) build a custom UITableViewCell class.
I'm new to objective C, and I wo开发者_Python百科uld essentially like to know if theres a third option that isnt as inefficient as #1, but not as involved as #2.
Thanks
Use the cell's tag
property (works only if your identifier is an integer).
That said, cells already have a unique identifier (albeit not necessarily constant) and that is their indexPath
, i.e. their position in the table. You should generally not use the cells to store any data directly. Instead, store the data in a model object and maintain the connection between model data and view via the indexPath.
This is especially important when dealing with table views as cell views get reused or deallocated as soon as a cell is scrolled off the screen.
精彩评论