【发布时间】:2013-11-25 10:09:12
【问题描述】:
我正在我的应用程序的文件夹 Documents 中寻找 png 文件,并将它们的标题添加到数组中。调用函数后数组还是空的。你能帮助我吗?我是 Obj-C 的初学者。谢谢。
我的功能:
-(void)getphotolist{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSBundle *myBundle = [NSBundle bundleWithPath:documentsDirectory];
NSArray *mypngs = [myBundle pathsForResourcesOfType:@".png"
inDirectory:documentsDirectory];
NSMutableArray *photo_array = [[NSMutableArray alloc] init];
NSLog(documentsDirectory);
for (NSString *tString in mypngs) {
[photo_array addObject:tString];
for (id obj in photo_array)
{
NSLog(@"obj: %@", obj);
}
}
}
【问题讨论】:
-
试试this
-
NSLog(@"%@", filesDirectory); - 应该是这样的
-
@user3030843 试试我更新的答案。它应该在数组中给出所有 png 文件的名称。
-
应该是:[myBundle pathsForResourcesOfType:@".png" inDirectory:nil];
标签: ios objective-c