-1

I want to read some remote pdfs so I create an NSArray containing the urls, but when I try to read it I get this:

Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 2 beyond bounds [0 .. 0]'

this is my code

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

    if ([[segue identifier] isEqualToString:@"CircularDetail"]) {

        CircularDetailViewController *circulardetail = [self.storyboard instantiateViewControllerWithIdentifier:@"CircularControllerDetail"];

        NSIndexPath *myIndexPath = [self.tableView indexPathForSelectedRow];
        int row = [myIndexPath row];

        circulardetail.DetailModal = [NSArray arrayWithObjects:_SeccionCirculares[row], _circularfecha[row], _circularTitulo[row], _circularURL[row], nil];

        [self presentViewController:circulardetail animated:YES completion:nil];
    }
}

in the detail I have this

- (void) loadRemotePdf
{
        NSURL  *myUrl = [NSURL URLWithString:[_DetailModal objectAtIndex:3]];
        NSURLRequest *myRequest = [NSURLRequest requestWithURL:myUrl];

        [self.webview loadRequest:myRequest];
}
Wain
  • 118,658
  • 15
  • 128
  • 151
  • You have several arrays - what's in them? Which one fails? Log the array contents each time before you access the array. Check the array `count` before accessing the contents. – Wain Feb 08 '14 at 17:21

1 Answers1

0
CircularDetailViewController *circulardetail =
     [self.storyboard instantiateViewControllerWithIdentifier:@"CircularControllerDetail"];

creates a new instance of the view controller. You probably want

CircularDetailViewController *circulardetail =
     (CircularDetailViewController *)[segue destinationViewController];

instead.

And you don't have to call presentViewController for a segue transition.

You should also note that any nil object in the argument list of

circulardetail.DetailModal = [NSArray arrayWithObjects:...];

terminates the list, so the array might be shorter than you expect.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382