UIImages 不显示在 iPhone 上的 TableView 中,但在 Simulator 中工作

发布于 2024-08-30 01:58:52 字数 556 浏览 5 评论 0原文

我有一个 UITable 视图,它在表格单元格的左侧显示图像,并且它在模拟器中工作正常。

唯一的问题是,一旦我在我的设备上运行它,就不会出现图像。这只是一个空白区域。

已检查图像是否已添加到用于构建的资源文件夹(它们就是),并且大写字母等是否匹配(它们确实如此)。

有什么想法吗?

谢谢。

显示图像的代码:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

忱杏 2024-09-06 01:58:52

这是图像的问题,而不是您的代码的问题(如果它们显示在模拟器中)。很多时候图像的格式不正确(以便 iPhone 可以理解),并且很多时候重命名效果不好(假设您更改了扩展名而不更改格式)。

你不能将模拟器与iPhone进行比较,因为模拟器利用了mac-os的优势,所以它可以做一些iPhone不能做的事情。

因此,这个故事的寓意是重新创建您的图像,并使用其他一些图像(已在其他项目的设备上显示的图像)检查您的代码。

谢谢,

马杜普

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

总攻大人 2024-09-06 01:58:52

检查您在 XCode 中运行的 iPhone SDK 版本。

它应该与您的 iPhone 所包含的 iPhone 操作系统相同。

可能这就是问题所在......

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

浅忆流年 2024-09-06 01:58:52

如果您想尝试,您可以使用另一种解决方案来获取圆形图像:

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

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]];
流年里的时光 2024-09-06 01:58:52

用此替换您的代码并查看控制台中的登录:

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

NSLog(@"%@",strImgName);

UIImage *image = [UIImage imageNamed:strImgName];

并查看您获得的图像名称并将其与资源文件夹中的实际图像匹配...它应该相同(即 apple.png = apple.png),包括*.扩展名

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

别在捏我脸啦 2024-09-06 01:58:52

如果图像位于资源组中,请尝试此操作。

UIImage *cellImage = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[[狗类型] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] ofType:@"png"]];

Try this, if image is in the resource group.

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

默嘫て 2024-09-06 01:58:52

我知道,现在这是一篇相当老的帖子了,但我想我必须在某个地方分享我的问题是什么,

在我的例子中,我有以下代码,

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

但我的图像被命名为“some-background.png”。

在模拟器中一切看起来都很好,但在手机上我没有背景。好像模拟器不区分大小写,而iPhone则不区分大小写。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文