Managing data for UITableViews
صفحه اصلي

Managing data for UITableViews



I have two very simple, identical UITableViews in my app that are populated with thumbnail images named "thumb1.jpg", "thumb2.jpg", etc. These thumbnails have associated original images "1.jpg" and text files "1.txt" used for image processing. Everything is stored in the app's Documents folder.

I want to keep the numbered, ordered naming for these files since it makes displaying the thumbnails in the UITableViews very easy with cellForRowAtIndexPath. I'm currently using a NSMutableArray (index: 1 object:"thumb1.jpg", etc) to track all images in the app.

The issue is that users can add/delete images so maintaining the order is important. For handling adding/deleting I'm looking at using insertObjectAtIndex and removeObjectAtIndex on the NSMutableArray, which will maintain order but will require programmatically changing image and text file names when this happens. For example, if there are five images in the array "0.jpg","1.jpg","2.jpg","3.jpg","4.jpg" and the user deletes the second image ("1.jpg") the array will now have "2.jpg" at index 1 so filenames will have to be changed to "1.jpg", "1.txt", and "thumb1.jpg".

How does this approach sound? I'm new to Objective-C so if you have other functions you'd use, etc I'd be interested to hear your opinion.


How to parse nested JSON objects with JSON framework and Objective-C/iPhone/Xcode?

1:

NSArray (and other containers) behavior on dealloc
Renaming the actual image files themselves doesn't sound like a good idea.. Using directory with WebViewUI I would implement 2 NSMutableArrays, one to hold the title/description of the image and one to hold the filename (or, if you wanted, the actual UIImage instead). iphone-sdk, sharing data between multiple views Then if you need to delete, for case the item at index 2, deleting the same object from each of the two arrays will then leave them in sync.. Some beginner Objective-C/iPhone questions If you start wanting more and more things to be stored for each row, I suggest you implement your own class. How can I make an sort of multidimensional associative array in objective-c / UIKit? You must then implement an array of multiple instances of this class, and each class would have properties such as image, text, thumbnail etc. How do I access a super classes instance var? In fact, for the reason this you've already named three separate properties (main image, text and thumbnail) I'm tempted to say you should implement a custom class straight away.. Cross-Platform Way of Creating Safari Webarchives Let me know if this makes sense or if you'd like any code to further illustrate it..


86 out of 100 based on 51 user ratings 646 reviews

*