Due to memory management issues I am using imageWithContentsOfFile
instead of imageNamed
, but I'm having issues accessing the images stored in Images.xcassets
folder.
I have values stored in an NSDictionary
that corresponds to the image name within the Asset library
, i.e. image1, image2, etc.
viewDidLoad:
{
images = @{@"01" : @"image1",
@"02" : @"image2",
@"03" : @"image3"
//more keys and values };
numbers = [ [contestants allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
// code to set up the cell
NSString *number = [numbers objectAtIndex:indexPath.row];
NSArray *nameByNumber = [images objectForKey:number];
NSString *name = [nameByNumber objectAtIndex:indexPath.section];
cell.imageView.image = [UIImage imageWithContentsOfFile: [ [NSBundle mainBundle] pathForResource:name ofType:@"png"] ];
return cell;
}
However, the cell is empty, no image. I even tried to hard-code the NSString pathForResource
, but nothing?
How can I achieve this using Asset Catalog
?
Thanks