Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

nashyo

macrumors 6502
Original poster
My code works fine on the simulator. However, I'm getting this error message when running on the iPhone 4S:

2012-04-25 12:30:24.702 Design3RCGP[1812:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary setObject:forKey:]: attempt to insert nil value (key: cellImage)'

For this code:
Code:
- (void)viewDidLoad
{
    NSMutableDictionary *dictionary1 = [NSMutableDictionary dictionaryWithCapacity:3];
    NSMutableDictionary *dictionary2 = [NSMutableDictionary dictionaryWithCapacity:3];
    NSMutableDictionary *dictionary3 = [NSMutableDictionary dictionaryWithCapacity:3];
        
    [dictionary1 setObject:[[NSString alloc] initWithString:@"Podcasts"] forKey:@"cellName"];
    [dictionary1 setObject:[UIImage imageNamed:@"PodcastIcon"] forKey:@"cellImage"];
    
    [dictionary2 setObject:[[NSString alloc] initWithString:@"Briefings"] forKey:@"cellName"];
    [dictionary2 setObject:[UIImage imageNamed:@"essentialicon"] forKey:@"cellImage"];
    
    [dictionary3 setObject:[[NSString alloc] initWithString:@"Essential Updates"] forKey:@"cellName"];
    [dictionary3 setObject:[UIImage imageNamed:@"EKnUpdIcon"] forKey:@"cellImage"];
    
    array = [[NSArray alloc] initWithObjects:
              dictionary1,
              dictionary2,
              dictionary3,
              nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [array count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static Temp1Cell *cell;
    static NSString *CellIdentifier = @"Cell";
    
    if (!cell) {
        cell = [[Temp1Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    cell = (Temp1Cell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    NSDictionary *dictionary = [array objectAtIndex:indexPath.row];
    
    cell.mainLabel.text = [dictionary objectForKey:@"cellName"];
    cell.imageView.image = [dictionary objectForKey:@"cellImage"];
    
    return cell;
}

This works fine on the simulator. Why?
 
Your code is failing on one of these lines:
Code:
    [dictionary1 setObject:[UIImage imageNamed:@"PodcastIcon"] forKey:@"cellImage"];
    
    [dictionary2 setObject:[UIImage imageNamed:@"essentialicon"] forKey:@"cellImage"];
    
     [dictionary3 setObject:[UIImage imageNamed:@"EKnUpdIcon"] forKey:@"cellImage"];

Because you're not loading the image successfully, hence trying to insert nil into the dictionary
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.