I have this code to add a row to a table view in the root view controller of my application:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSArray *myArray = [NSArray arrayWithObject:indexPath];
NSLog(@"count:%d", [myArray count]);
[self.tableView insertRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
When it is run with the simulator I get this output:
count:1
* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
This is occurring at the [self.tableView insertRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
line, but the NSLog
statement shows that the NSArray
called myArray
is not empty. Am I missing something? Has anyone ever encountered this before?