How to populate a UITableViewCell with the correct resolution image?

怎甘沉沦 提交于 2020-01-14 13:37:28

问题


I have set up a UITableView that contain cells of images.

I am using Asset Catalog to name the images appropriately as image1.png, image1@2x.png, and image1@3x.png.

I have an NSMutableArray that I initialize with the image names from Asset Catalog, for example like so:

viewDidLoad:

self.LogoArray = [ [NSMutableArray alloc] initWithObjects:@"image1",@"image2", image2", nil];

Then I created a Custom Cell with my own custom image to display in the cell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // some code here

    cell.customImageView.image = [UIImage imageNamed:[self.LogoArray objectAtIndex:indexPath.row] ];

    // some code here
}

The problem is when I run this on the different iPhone platforms, the images are really blurry and resolution is bad.

I believe the compiler doesn't know which version of image.png, image@2x.png, or image@3x.png to assign to cell.customImageView.image based on what iPhone platform it is running on.

Is there another alternative I should be using to allow Xcode to choose the appropriate image file from Asset Catalog to display it correctly on the different iPhone platforms?

This is how my Asset Catalog looks:

The objects in the LogoArray are named appropriately with the correct name from Asset Catalog.

Thanks


回答1:


You don't need to know the name of the file under the Asset Catalog.

In the screenshot you sent, you should just use the names:

self.LogoArray = [[NSArray alloc] initWithObjects:@"barona_logo", @"chase_logo", @"crabhut_logo", nil];

And you should be ok.



来源:https://stackoverflow.com/questions/27564450/how-to-populate-a-uitableviewcell-with-the-correct-resolution-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!