views:

396

answers:

6

Hi,

I have a UITable View that displays an image in the left hand side of the table cell, and it works fine in the simulator.

Only problem is, once I ran it on my device no images appear. It's just a blank white space.

Have checked that images are added to resource folder for build (which they are) and that capitals etc. match (which they do).

Any ideas?

Thanks.

Code to display images:

cell.imageView.layer.masksToBounds = YES;
    cell.imageView.layer.cornerRadius = 5.0;

    UIImage *image = [UIImage imageNamed:[[dog types] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];;
    if ( image ) {
        cell.imageView.image = [image imageScaledToSize:CGSizeMake(50, 50)];
    }
A: 

This is the problem of images, not your code (if they are showing in the simulator). Many times when the images are not in proper format (so that iPhone can understand) and many times the renaming does the bad job (suppose you have changed the extension without changing the format).

You can not compare a simulator with iPhone, because simulator takes advantages of mac-os, so it can do some things that iPhone can't.

So the moral of the story is re-create your images, and check your code with some other images(images that had been showing on device in other projects).

Thanks,

Madhup

Madhup
They're PNG files though - and three of them were showing until I cleaned the header files.
Graeme
A: 

Hi, Graeme

Check the iPhone SDK version on which you are running in XCode.

it should be same as the iPhone OS of your iPhone contains.

May be this was the issue...

yakub_moriss
Hmm, have checked, doesn't seem to be an issue - both match.
Graeme
hi, GraemeUIImage *image = [UIImage imageNamed:[[dog types] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];;in this line check the name of image(in debug mode) what you are getting and the image name what is Actually has in resource folder.it should be mached...
yakub_moriss
How would you suggest I do this? Thanks.
Graeme
image not displyed without any error means it can't find the image in resource folder...ensure the image name(in debug mode) including image type (*.png) thats the reasone for the "blank white space" which you have said in your Que...bcose previously i already face this type of problem...
yakub_moriss
Yeah what do I do in debug mode though to check?
Graeme
check what image name you are getting in your code in line :UIImage *image = [UIImage imageNamed:[[dog types] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];;see my other answer
yakub_moriss
Yeah but what do I enter in the debug console to check at the breakpoint?
Graeme
A: 

I have the same problem, but the same image appears in a viewController imageView created in IB (as opposed to progamatically in Xcode). The simulator works ok but the device doesn't. Hmmm...

Billy
A: 

hello, Graeme

you can have another sollution for getting rounded images if you want to try :

UIImageView * roundedView = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@"wood.jpg"]];
// Get the Layer of any view
CALayer * l = [roundedView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];

// You can even add a border
[l setBorderWidth:4.0];
[l setBorderColor:[[UIColor blueColor] CGColor]];
yakub_moriss
Although this works for most `UIView`s, I don't think you can do this with a `UIImageView` due to `UIImageView`'s internal implementation.
Nick Forge
A: 

Hi, Graeme

replace you code with this and see the log in console :

NSString *strImgName = [[dog types] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];

NSLog(@"%@",strImgName);

UIImage *image = [UIImage imageNamed:strImgName];

and see what you are getting as an image name and mach it with your actual image in resource folder...it should be same (i.e. apple.png = apple.png) including *.extensions

yakub_moriss
+1  A: 

Try this, if image is in the resource group.

UIImage *cellImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[[dog types] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ofType:@"png"]];

Kundan Pandit
if it doesn't work, then must be your images not in proper format. Use preview to change it to desired one.
Kundan Pandit