Quote:
Originally Posted by WTFWJD
Hi
Bit of a newbie question here. I'm trying to make a one row table view -> detail view app. The table is an alphabetical list of items and the detail view is a corresponding image of those items; ie.
User taps Apple in table view - detail view shows picture of an apple
User taps 'Back' button and is returned to the table view
User taps Bicycle in table view - detail view shows picture of a bicycle
Etc...
Am I right in thinking that I can store the list of items and corresponding images in a single plist file that is used to populate the table view and the detail view? ie.
Root (Array)
Item 1 (Dictionary)
name (String) Apple
image(String) apple.png
Item 2 (Dictionary)
name (String) Bicycle
image(String) bicycle.png
Etc...
If so, is a Navigation-based Application template in Xcode the best place to start? Or will I need to write custom code to access the plist in this way?
Any help or advice would be greatly appreciated, many thanks!
|
You've got the right idea. A plist would be one way to save your data and read it at start time. A plist will archive/unarchive dictionaries or NSArray objects. However, those dictionaries/arrays can only contain a small list of data types (including mutable or immutable variants)
NSDictionary
NSArray
NSData
NSString
NSNumber
Your image files can't be stored into a plist directly.
The simplest way to handle that is to just store the filenames of your images into your plist, and save the images as separate files in your app bundle. Then, when you need one, load it using UIImage imageNamed:
Loading your plist is really trivial. Just use the NSArray method +arrayWithContentsOfFile:
The same goes with saving your array. To save it, call the NSArray object writeToFile:atomically:
Given that you want to have a table view that links to a detail view, and then lets the user go back to the table view, a navigation based application sounds perfect. In your table view controller, you'd just use the method pushViewController:animated: to push your detail view controller, and then pop it off when you want to go back to your table view controller.
Regards,
Duncan C
WareTo