I've checked the other posts, but non seem to answer my question, so here I go :)
I've got a Plist, with the following contents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>001</key>
<dict>
<key>Name</key>
<string>Name1</string>
<key>Number</key>
<string>001</string>
</dict>
<key>002</key>
<dict>
<key>Name</key>
<string>Name2</string>
<key>Number</key>
<string>002</string>
</dict>
</dict>
</plist>
I'm trying to get this code to converted to an array and used for a TableView source. However, even thought I've seen other posts, none help me out (That I can see, this is my first true iOS Project, so I might not be 100% at manipulating their code). I want the table to be generated from this Plist, and since it's going to have at least 100 items (With more being added via the Plist), I'd like for it to be generated.
However, the main thing I'm struggling to do is get the array to get the information from Key1, then Key2, Key3... like it would in the following manual code (Which I have to type out manually, and I'll be adding more info, so I want it to come from the Plist):
NSDictionary *item1 = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Name1", @"Name", @"001", @"Number", nil];
NSDictionary *item2 = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Name2", @"Name", @"002", @"Number", nil];
NSDictionary *item3 = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Name3", @"Name", @"003", @"Number", nil];
One thing I would like is to be able to change the order the table is shown in (Between number and alphabetic), which I don't think is hugely relevant, but it's something I'd like to throw in there, incase I'm making a mistake with something meaning that can't be done?
Thank you for reading,
Joseph Duffy
Edit: Solved, but new issue, please read below. Now solved, thank you! Thank you for the information, it has been most useful! However, when I put the following:
- (void)viewDidLoad
{
NSBundle *bundleLocation = [NSBundle mainBundle];
NSString *arrayLocation = [bundleLocation pathForResource:@"plistname" ofType:@"plist"];
NSArray *plistcontentsArray = [[NSArray alloc] initWithContentsOfFile:arrayLocation];
self.pokemonNames = pokemonArray;
[bundleLocation release];
[plistArray release];
[super viewDidLoad];
}
Everything works fine. But when I add [arrayLocation release];
it crashes with "exc_bad_access". Any ideas? :)