I have this code to add a row to a table view in the controller of the root view 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 starts with the simulator, I get this output:
quantity: 1
* Application termination due to an uncaught exception "NSRangeException", reason: "* - [NSMutableArray objectAtIndex:]: index 0 outside for an empty array
This happens on the line [self.tableView insertRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade]; but the NSLog statement shows that an NSArray called myArray is not empty. Am I missing something? Has anyone ever come across this before?
source share