【发布时间】:2011-07-08 00:53:42
【问题描述】:
我将字符串(即某个目录中文件的文件名)放入带有 for 循环的 NSMutableArray 中: h 文件:
#import <Three20/Three20.h>
@interface AlbumController : TTThumbsViewController {
NSMutableArray *images;
}
@property (nonatomic, retain) NSMutableArray *images;
@end
m 文件:
#import "AlbumController.h"
#import "PhotoSource.h"
#import "Photo.h"
@implementation AlbumController
@synthesize images;
-(void)createPhotos {
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRoot error:nil];
NSArray *onlyJPGs = [dirContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.jpg'"]];
NSMutableArray *pics = [[onlyJPGs copy] autorelease];
if(!self.images) {
self.images = [[NSMutableArray alloc] init];
}
for(int i = 0; i < [onlyJPGs count]; i++)
{
//NSLog([pics objectAtIndex:i]);
NSString *ImgURL = [@"bundle://" stringByAppendingString:[pics objectAtIndex:i]];
Photo *photo = [[Photo alloc] initWithURL:ImgURL smallURL:ImgURL size:CGSizeMake(320, 212)];
[images addObject:photo];
[photo release];
}
}
-(void)viewDidLoad{
[self createPhotos]; // method to set up the photos array
self.photoSource = [[PhotoSource alloc]
initWithType:PhotoSourceNormal
title:@"Chili Pflanzen"
photos:images
photos2:nil
];
}
@end
我在模拟器上没有任何问题,但在我的 iPod 上...
错误信息:
数据格式暂时不可用,将在“继续”后重试。 (加载共享库“/Developer/usr/lib/libXcodeDebuggerSupport.dylib”时出现未知错误)
提前致谢
【问题讨论】:
标签: objective-c ios4 memory-leaks for-loop nsmutablearray