0

I'm trying to access an UIImage instance variable and display it in UIImageView. When I try to NSLog the path I get null. I can manually display a pic through the IB, but I want to do this strictly through code

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

I've added a link to show where the pics are found

Link

blitzeus
  • 485
  • 2
  • 10
  • 28

1 Answers1

0

You don't have to include all the path to the image, if you just put the name, Xcode will automatically look for it.

pcs289
  • 129
  • 4