开发者

UIImages not displaying in TableView on iPhone, but working in Simulator

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, 开发者_JAVA百科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)];
    }


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


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...


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]];


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


Try this, if image is in the resource group.

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


I know, that's quite an old post now, but I think I have to share what my problem was, somewhere

In my case I had the following code

UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"some-Background.png"]];
[tempImageView setFrame:self.tableView.frame];
[self.tableView setBackgroundView:tempImageView];

but my Image was named "some-background.png".

In the simulator everything looked fine, but on the phone I got no background. It seems that the simulator is case insensitive, whereas the iPhone is not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜