prof
prof

Reputation: 21

UIImage:imageNamed on ipad fails ok in simulator

The following code snippet works fine using the iPad simulator and iphone simulator. However the UIImage is nil (checked whilst debugging) when I run it on my ipad 2 (using iphone mode)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:@"flowerCell"];

    switch (indexPath.section) {
        case kRedSection:
            cell.textLabel.text=[self.redFlowers objectAtIndex:indexPath.row];
            break;

        case kBlueSection:
            cell.textLabel.text=[self.blueFlowers objectAtIndex:indexPath.row];
            break;

        default:
            cell.textLabel.text=nil;
    }

    NSString *img=[[NSString alloc] initWithFormat:@"%@%@", cell.textLabel.text, @".png"];

    UIImage *flowerImage=[UIImage imageNamed:img];

    cell.imageView.image=flowerImage;

    return cell;
}

This is a billy basic iphone example taken from a tutorial book and is the 1st time this problem has arisen.

Upvotes: 0

Views: 229

Answers (2)

Eric
Eric

Reputation: 7877

I assume if its not the file name capitalization the image is missing.

The simulator may be masking the problem by cacheing resources. If you delete the app from the simulator, clean, and run again you will probably see the same issue on the simulator.

Check your targets build settings and see if the image is in your resources.

Upvotes: 1

mohammad alabid
mohammad alabid

Reputation: 444

Try to match exactly image name Lowercase-uppercase

if the image name is "image.png" and you write the name in the code @"image.Png" this will work fine on simulator and will not work on Device

Upvotes: 2

Related Questions