I'm trying to use a UITableViewController (delegate & dataSource for the view) to display a simple table read from a Plist. The Plist contains a NSDictionary which itself contains several NSDictionary objects that represent objects used in my application.
The rest of the code looks something like this (simplified):
- (void)viewDidLoad {
[super viewDidLoad];
[self loadObjectsFromPlist];
}
- (void)loadObjectsFromPlist {
NSString *objectPlistFile = [[NSBundle mainBundle] pathForResource:@"Objects" ofType:@"plist"];
NSDictionary *objectsDictionary = [NSDictionary dictionaryWithContentsOfFile:objectsPlistFile];
objects = [[NSMutableArray alloc] init];
NSEnumerator *objectEnumerator = [objectsDictionary objectEnumerator];
NSDictionary *objectData;
while(objectData = [objectEnumerator nextObject]) {
[objects addObject:[MyObject objectFromDictionary:objectData]];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [objects count];
}
As I'm not using any sections I return 1
in numberOfSectionsInTableView
of the controller.
The objectFromDictionary
method of "MyObject
" assigns the data read from the NSDictionary
to a new object. I tried retaining, copying etc. too, but that didn't change anything.
I get a EXC_BAD_ACCESS
in tableView:numberOfRowsInSection
when calling [objects count]
. I tried using the Object Allocation Instrument, but I didn't find a problem. My Plist currently contains only data for one object. The Debugger displays "1 objects" in red color for the objects
attribute, so I think this is related to the problem.