我正在尝试访问 UIImage 实例变量并将其显示在 UIImageView 中。当我尝试 NSLog 路径时,我得到空值。我可以通过 IB 手动显示图片,但我想通过代码严格执行此操作
#import "Deck.h"
#import "Card.h"
@implementation Deck
@synthesize cards;
- (id) init
{
if(self = [super init])
{
cards = [[NSMutableArray alloc] init];
NSInteger aCount, picNum = 0;
for(int suit = 0; suit < 4; suit++)
{
for(int face = 1; face < 14; face++, picNum++)
{
NSString *fileName = [NSString stringWithFormat:@"card_%d", picNum];
NSString *path = [[NSBundle mainBundle] pathForResource:fileName
ofType:@"png"inDirectory:@"/cards"];
NSLog(@"%@", path); //outputs correctly
UIImage *output = [UIImage imageNamed:path];
NSLog(@"%@", output); //outputs null
Card *card = [[Card alloc] initWithFaceValue:(NSInteger)face
countValue:(NSInteger)aCount
suit:(Suit)suit
cardImage:(UIImage *)output];
[cards addObject:card];
}
}
}
return self;
}
我添加了一个链接来显示图片的位置