I use the example on page 210 of the book “iPhone Design” (“Exploring the iPhone SDK”) and it looks like what I want to do, but this specific example is complicated by the use of partitions in TableView. I have a specific hierarchy in my plist ...
Root ---- Dictionary
Rows ---- Array
Item 0- Dictionary
fullName ---- String
address ---- String
Item 1 ---- Dictionary
fullName ---- String
address ---- String
So, I have a UITableView that takes up a small portion of the view on this “screen”. The rest of the view has other elements, so I selected a nut to use the navigation template.
The code I use does not match, because I really don’t understand which fields to call.
Can someone show me a VERY simple example of how I could list all the "firstNames" in this table. If something is wrong with my plist, please let me know what will change.
In a nutshell, I want to iterate over all the Item # dictionaries to list all the first names. My project is like a contact list, but not exactly a contact list.
Right now I'm using this code that just displays the word "Lines". I changed the lines of words to Rows1 in my plist and found that it captures this "array element". I hope I said the right thing.
-(void)viewDidLoad {
NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
self.names = dict;
[dict release];
NSArray *array = [[names allKeys] sortedArrayUsingSelector:@selector(compare:)];
self.listData = array;
[super viewDidLoad];
}
-(NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return [self.listData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"Identifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [listData objectAtIndex:row];
return cell;
}
I tried the web for several days trying to find a simple example that uses the plist hierarchy to list items in a table that is not part of the navigation template.
Many thanks