我正在寻找文件夹中的png文件,并将它们的标题添加到数组中。调用函数数组后仍然是空的。你可以帮我吗?我是Obj-C的初学者。谢谢。正在搜索png文件iOS
我的功能:
-(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);
}
}
}
尝试[此](http://stackoverflow.com/a/14110339/940096) – Praveenkumar
的NSLog(@ “%@”,documentsDirectory); - 应该是这样 –
@ user3030843尝试我更新的答案。它应该给数组中的所有png文件名称。 –