我在支持文件中有一個名爲「cards」的文件夾。我正在嘗試將pic設置爲對象的UIImage實例變量。當我嘗試NSLog的UIImage我得到空。將圖片設置爲UIImages作爲實例變量
我不認爲我正確訪問圖片的路徑,但不知道?
#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 *path = [[NSBundle mainBundle] bundlePath];
//NSString *imagePath = [path stringByAppendingPathComponent: [NSString stringWithFormat:@"/cards/card_%d.png",picNum]];
NSString *fileName = [NSString stringWithFormat:@"card_%d", picNum];
NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"png"inDirectory:@"/cards"];
NSLog(@"%@", path);
UIImage *output = [UIImage imageNamed:path];
//NSLog(@"%@", output);
Card *card = [[Card alloc] initWithFaceValue:(NSInteger)face
countValue:(NSInteger)aCount
suit:(Suit)suit
cardImage:(UIImage *)output];
[cards addObject:card];
}
}
}
return self;
}
}
@end
你爲什麼要鑄造的'每一個參數 - [Card init ...]'? – 2012-12-28 16:03:39
它在一個循環初始化52卡對象,然後將它們添加到一個數組,我只是沒有發佈所有的代碼 – blitzeus