Reputation: 701
So I just got this error after trying to access the SECOND item in my array. When I access the first item in my array in my table view cell nothing is wrong. But when I access the 2 cell / item in my array I get this error:
Terminating app due to uncaught exception 'NSRangeException', reason: '* **-[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
My breakpoints tell my my code is breaking at my prepareForSegue method. Can anyone please help me figure out what's wrong with my code?:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"Push"]) {
HistoryDetailsViewController *detailVC=(HistoryDetailsViewController*)segue.destinationViewController;
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
if (indexPath.section == 0)
{
NSManagedObject *YouOweData = [YouOweArray objectAtIndex:indexPath.row];
[detailVC setCellNumString:[NSString stringWithFormat:@"%@", [YouOweData valueForKey:@"youOweCellNum"]]];
[detailVC setDateString:[NSString stringWithFormat:@"%@", cell.detailTextLabel.text]];
}
else if (indexPath.section == 1)
{
NSManagedObject *TheyOweData = [SomeonesOwesYouArray objectAtIndex:indexPath.row];
[detailVC setCellNumString:[NSString stringWithFormat:@"%@", [TheyOweData valueForKey:@"theyOweCellNum"]]];
[detailVC setDateString:[NSString stringWithFormat:@"%@", cell.detailTextLabel.text]];
}
}
}
All help is appreciated, thanks in advance
Upvotes: 0
Views: 70
Reputation: 701
Ah, I fixed the problem. The reason my array was null was because it was grabbing objects that weren't even there. My viewDidAppear method BELOW it was grabbing the contents, so I cut and pasted it ABOVE the prepareForSegue
Upvotes: 1