The chapter 10 reply is a little more in depth, and caused by the same issue - an additional layer in the plist. A dictionary containing a dictionary of arrays, instead of just a dictionary of arrays.
The following demonstrates what is going on, with added lines and comments in
bold
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
NSLog(@"self.years is class%@\nThe contents of years is %@", [self.years class], self.years); //The array contains one object a dictionary called "Root" not the list of years as planned
NSString *year = [self.years objectAtIndex:[indexPath section]];
NSLog(@"year is %@",year); // Year is not a year, it is the only key "Root"
NSLog(@"self.movieTitles is %@",[self.movieTitles class]); //movieTitles is a dictionary as expected
NSArray *movieSection = [self.movieTitles objectForKey:year];//The objectForKey:year is the object for key "Root" which is a dictionary, not an array
NSLog(@"movieSection contents %@\nmovieSection class %@",movieSection, [movieSection class]); // listing the contents - it is a dictionary of the year arrays and their movie strings. The class is __NSCFDictionary
cell.textLabel.text = [movieSection objectAtIndex:[indexPath row]];//Crash because movieSection is supposed to be an array and is not - it is a dictionary. The dictionary class does not have an "objectAtIndex:" method
return cell;
}
To resolve the problem the extra layer in the plist needs to be removed. See
http://p2p.wrox.com/271591-post2.html
for the simplest way to do this.
Bob