我正在尝试访问UIImage实例变量并在UIImageView中显示它。当我尝试NSLog路径时,我得到null。我可以通过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;
}
我添加了一个链接来显示找到图片的位置
答案 0 :(得分:0)
您不必包含图像的所有路径,如果您只是输入名称,Xcode会自动查找它。