Managing arrays for a UITableView
I have an array of an object type that has different text fields to display in a custom UITableViewCell. This custom object type also has an image to be displayed as an imageview. Unfortunately, the size isn't the same for the images. In my viewDidLoad, I have a method to create a thumbnail image for all the images making them the same size. I store this in a new array to not mess with the original data that is used in other parts of the app. This works fine in the display of the table, however, if I want to sort by one of the particular NSString fields, how do I keep t开发者_如何学Crack of where that new data goes to go along with the correct picture. A simple example would be:
firstName, lastName, picture I have a new array that has the pictureThumbnails. if the default is firstName, pictureThumbnails will display in order.
If I resort and change my array for my data to go by lastName, firstName, picture picture will no longer align with the right person. What do I need to do in order to keep track of the position changes in the table? Thanks!
It may not be a bad idea to create an NSObject
for each instance with attributes for firstName, lastName and picture. You can store the objects in an array and sort by whichever field you choose, but are ensured that the correct information stays with the correct picture
This just sounds like a headache to me. Unless you have a particular reason for not doing so, I would add thumbnail
as another property of your custom object, and store the image there.
精彩评论