0

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;
}

写真が見つかった場所を示すリンクを追加しました

リンク

4

1 に答える 1

0

画像へのすべてのパスを含める必要はありません。名前を入力するだけで、Xcode が自動的に検索します。

于 2013-01-07T23:34:04.153 に答える