I am new to objective-C and Xcode and I am trying to pass an array row index using the “prepareforsegue” method in the master viewcontroller. I am then plugging the index value into a small sqlite3 table so the detail viewcontroller shows the correct data row. Project has no errors but crashes with:
‘NSRangeException’, reason: ‘* -[__NSArrayM objectAtIndex:]: index 6194506 beyond bounds [0 .. 1]’
Here is the prepareforsegue code:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showDetail"])
{
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
FEIViewController *destViewController = segue.destinationViewController;
NSInteger row = selectedRowIndex.row;
destViewController.rowNumber = &(row);
}
}
Here is the viewDidLoad code:
- (void)viewDidLoad
{
int myRowInt = *(_rowNumber);
FEIMyList * myFEI =[[FEIMyList alloc] init];
self.feig = [myFEI getMyFEI];
[self.feigImage setImage:((FEIList *) [self.feig objectAtIndex:myRowInt]).image];
[self.feigAction setText:((FEIList *) [self.feig objectAtIndex:myRowInt]).action];
[self.feigOther setText:((FEIList *) [self.feig objectAtIndex:myRowInt]).other];
[self.feigCondition setText:((FEIList *) [self.feig objectAtIndex:myRowInt]).condition];
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
Your myRowInt is being set incorrectly. Try creating an NSNumber as a property on the destination view controller and then setting it in prepareForSegue.