我在HSImageSidebarView
开源项目中包含的示例中使用 and ,这是在边栏中加载图像的方法:
-(UIImage *)sidebar:(HSImageSidebarView *)sidebar imageForIndex:(NSUInteger)anIndex {
int color = [[colors objectAtIndex:anIndex] intValue];
switch (color % 3) {
case 0:
return [UIImage imageNamed:@"Blue"];
break;
case 1:
return [UIImage imageNamed:@"Red"];
break;
default:
return [UIImage imageNamed:@"Green"];
}
}
我的问题是如何从NSDocumentDirectory
. 这是我的数组:
self.images = [NSMutableArray new];
for(int i = 0; i <= 100; i++)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"Images%d.png", i]];
NSLog(@"savedImagePath=%@",savedImagePath);
if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){
[images addObject:[UIImage imageWithContentsOfFile:savedImagePath]];
NSLog(@"file exists");
}
NSLog(@"file does not exist");
}
谢谢您的帮助!