I want to populate a TableView with data from a database and, when tap a cell, in didSelectRowAtIndexPath, sending selected ID to a new View.
I would like to view, in cell text, the description of the record and to put ID in a hidden field/property of the cell, but I could not find a way to do it.
I know I can get an ID from the data source (something like [my_data_source objectAtIndex:indexPath.row]; ) but I don’t really like this way, I would prefer to have an ID assigned to a single cell.
Is there a way to do it?
Thanks in advance and greetings.
I’m guessing you’ve come from web development? I also found it difficult to do it this way, but its the best way. IT probably is possible – but its better if you get used to doing it like this, it really is.
Basically define an NSArray in the .h file (so the whole script can use it).
then in the init function:
then the table view delegate methods:
(disclaimer: these are just off the top of my head, and I haven’t checked the exact methods – they’re probably wrong in some way – but the code inside the functions is what you want really.)
When you’ve started using this you’ll see its so much better than “hiding” an id somewhere in a table. To get things from the database I would suggest adding it all to a dictionary, or an array or similar and doing it like that when you init the class, but if you really want to do it dynamically then pretend your “hidden” ids are just index’s of an array. So id#1 is at index 1 in your array. 🙂