0

my application uses .png images from the applications document's folder to show thumbnails at a later time in a pop up. I am trying to add all the .png images from the folder into an array. I know the error is happening when the tempImage object is added to the array, but I am unsure of why this is happening. Does anyone see the issue with this block of code?

NSArray *pathforsave = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [pathforsave objectAtIndex:0];


NSArray *getFiles = [[NSFileManager defaultManager]
                     contentsOfDirectoryAtPath:documentDirectory
                     error:nil];


NSInteger x = 0;


NSPredicate *fltr = [NSPredicate predicateWithFormat:@"self ENDSWITH '.png'"];
NSArray *onlyPNGs = [getFiles filteredArrayUsingPredicate:fltr];

NSMutableArray *Images;
NSUInteger arrayPNGLength = [onlyPNGs count];
for (x=0; x<arrayPNGLength; x++) {
    //first get the path
    NSString *strFile = [documentDirectory stringByAppendingPathComponent:[onlyPNGs objectAtIndex:x]];
    UIImage *tempImage = [ UIImage imageWithContentsOfFile: strFile];
    [Images addObject:tempImage];

}

Thanks for your help, I am new to objective c.

4

1 回答 1

4

NSMutableArray *Images = [[[NSMutableArray alloc] init] autorelease];

代替NSMutableArray *Images;

于 2012-10-10T16:44:07.870 回答