Note that there are some explanatory texts on larger screens.

plurals
  1. PONSRangeException Error with NSArray - While setting image view in another ViewController
    primarykey
    data
    text
    <p>I'm getting an image from the AppDelegate, then setting it to the ViewController's table.imageView property. It's throwing me an NSRangeException: </p> <pre><code>*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFArray objectAtIndex:]: index (2) beyond bounds (2)' </code></pre> <p>I made sure my array and rows are counted by [array count]. Very confused. Here's the code:</p> <pre><code>#pragma mark - viewWillAppear - (void)viewWillAppear:(BOOL)animated { PBAppDelegate *dataObject = (PBAppDelegate *)[[UIApplication sharedApplication] delegate]; NSString *titleRead = dataObject.title; NSString *descRead = dataObject.desc; UIImage *imageRead = dataObject.image; if ([titleRead isEqualToString:@"" ] || [descRead isEqualToString:@""]) { // it's nil } else { if (titleRead) { [data addObject:[NSArray arrayWithObjects:titleRead, descRead, imageRead, nil]]; dataObject.title = @""; dataObject.desc = @""; [tableView reloadData]; } NSUserDefaults *dataDefaults = [NSUserDefaults standardUserDefaults]; [dataDefaults setObject:[NSArray arrayWithArray:data] forKey:@"dataArrayKey"]; [dataDefaults synchronize]; } } #pragma mark - viewDidLoad - (void)viewDidLoad { [super viewDidLoad]; data = [[NSMutableArray alloc] init]; self.data = [[NSUserDefaults standardUserDefaults] objectForKey:@"dataArrayKey"]; [tableView reloadData]; } #pragma mark - Table Datasource - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"MyCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (!cell) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier]; } cell.textLabel.text = [[data objectAtIndex:indexPath.row] objectAtIndex:0]; cell.detailTextLabel.text = [[data objectAtIndex:indexPath.row] objectAtIndex:1]; cell.imageView.image = [UIImage imageNamed:[[data objectAtIndex:indexPath.row] objectAtIndex:2]]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload