I have a table view and when a user selects a cell I want to log a unique id. I thought I could use the index but the numbers are not sequential (I.e. 1,4,5,9,etc). Is there a way of defining a custom index or ID for a cell?
So I have the following cells in a table:
dog
cat
fish
the above cells have ids as below
2 dog
4 cat
8 fish
is there a way that when a user touches the fish cell it will return 8?
Indexpath.row would return 2 and I need 8. So is there a custom propertie I can set for each cell?
Not sure I totally understand the problem, but this should be ‘sequential’:
Update: Ok, so I think I get the confusion.
You need to have your dog, cat, fish, etc. in an NSArray that looks like [dog, cat, fish] that matches up with what you’re displaying on the screen, or else you’ll never be able to associate the two.
indexPath.row will be your pointer into that NSArray. So when you hit the second row, that code above will spit out 1. 1 in your array should your cat object, even though that’s not the cat’s id.
So then you do
to get your object, which in this case would be your cat. myAnimal.id will give you your 2.
Or, if your animals are dictionaries, it would be
would give you your 2.
Hopefully that helps a little more.