I have a table being generated from an array of NSManagedObjects. This works fine until I try to add an extra cell at the top of the table.
Here is what I'm trying at the moment:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
int menuLength = [mainMenu count] + 1;
return menuLength;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// Check for reusable cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: @"UITableViewCell"];
// If no reusable cell, create one
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault
reuseIdentifier: @"UITableViewCell"] autorelease];
}
// Set the text on the cell with the genus name that is at the nth index of generaList
if ([indexPath row] == 0) {
[[cell textLabel] setText: @"All"];
} else {
NSManagedObject *filter = [mainMenu objectAtIndex: [indexPath row]];
[[cell textLabel] setText: [filter valueForKey: @"filter_label"]];
}
return cell;
}
When I try to scroll through the table, it throws the following exception:
'NSRangeException', reason: '* -[_PFArray objectAtIndex:]: index (9) beyond bounds (9)'
Any help would be much appreciated!