开发者

Loading image files in Resources to NSMutableArray

开发者 https://www.devze.com 2023-02-09 03:46 出处:网络
I\'m building an app that randomly chooses and displays two images from bunch of images from Resources folder.

I'm building an app that randomly chooses and displays two images from bunch of images from Resources folder.

-(void)viewDidLoad {
    [super viewDidLoad];
    srandom(time(0));

    NSMutableArray *paths = [[[NSBundle mainBundle] pathsForResourcesOfType:@"jpg" inDirectory:nil] mutableCopy];

    for(NSString开发者_Go百科 *filename in paths)
    {
        filename=[filename lastPathComponent];
        [filenames addObject:filename];
    }

    [paths release];
    [self reset];
}

Checking for [paths count] returns successfully the number of images, but nothing is being allocated to filenames array.. filenames is an NSMutableArray and it is allocated in initWithNibName. What could be wrong? In addition, [paths count] is returning higher number than the actual number of images in Resources... which is kinda freaky.. I've spent so many hours trying to figure this out, but got stuck... Could anyone please help me???


Can you post your initWithNibName method? Also, I'm a little suspicious of your use of "filename". Try omitting that variable inside your for loop, like this:

for (NSString *filename in paths)
{
 NSLog("@ filename is %@", filename);
 [filenames addObject: [filename lastPathComponent]];
 NSLog(@" filenames array length is now %d", [filenames count]);
 }

What exactly is coming out of each filename in paths?

0

精彩评论

暂无评论...
验证码 换一张
取 消