Objective c 如何从具有特定名称的捆绑包中提取图像并添加到阵列中,

Objective c 如何从具有特定名称的捆绑包中提取图像并添加到阵列中,,objective-c,xcode,bundle,Objective C,Xcode,Bundle,在我的应用程序包中,我有几个项目的图像 ItemA_largepicture.png ItemA_smallPicture.png ItemA_overViewPicture.png ItemB_largepicture.png ItemB_smallPicture.png ItemB_overViewPicture.png ItemC_largepicture.png ItemC_smallPicture.png ItemC_overViewPicture.png 例如,我想提取所有Item

在我的应用程序包中,我有几个项目的图像

ItemA_largepicture.png

ItemA_smallPicture.png

ItemA_overViewPicture.png

ItemB_largepicture.png

ItemB_smallPicture.png

ItemB_overViewPicture.png

ItemC_largepicture.png

ItemC_smallPicture.png

ItemC_overViewPicture.png

例如,我想提取所有ItemB图片以显示在scrollView中。 我可以很容易地得到一个做如下

    path=[ItemB stringByAppendingString:@"_largePicture];
    NSString *imagePath=[[NSBundle mainBundle]pathForResource:path ofType:@"png"];
    UIImage *image=[UIImage imageWithContentsOfFile:imagePath];
    [self.image setImage:image];
所以问题很简单;如何获取所有ItemB图片?
我需要将它们放入数组中吗?我该怎么做呢?

这段代码应该列出mainBundle中的所有内容

largePicturePath=[ItemB stringByAppendingString:@"_largePicture];
smallPicturePath=[ItemB stringByAppendingString:@"_smallPicture];
overViewPicturePath=[ItemB stringByAppendingString:@"_overViewPicture];
NSString *largeImagePath=[[NSBundle mainBundle]pathForResource:largePicturePath ofType:@"png"];
NSString *smallImagePath=[[NSBundle mainBundle]pathForResource:smallPicturePath ofType:@"png"];
NSString *overViewImagePath=[[NSBundle mainBundle]pathForResource:overViewPicturePath ofType:@"png"];

NSArray *imageArray = [[NSArray arrayWithObjects:largeImagePath,smallImagePath,overViewImagePath,nil];

NSEnumerator *e = [imageArray objectEnumerator];

NSString *path;
while (path= [e nextObject]) {
    UIImage *image=[UIImage imageWithContentsOfFile:path];

    ...

}
NSString *bundleRootPath = [[NSBundle mainBundle] bundlePath];
NSArray *bundleRootContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRootPath error:nil];
NSArray *files = [bundleRootContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self beginswith 'ItemA' OR self beginswith 'ItemB' OR self beginswith 'ItemC'"]]; //you can provide your string in ' ' to filter specific content
NSLog(@"%@",files);

非常感谢你。这很有帮助。现在,我想知道你是否能帮助我更进一步。假设所有ItemA图像都位于名为“ItemA”的文件夹中,以此类推。我猜应该使用“bundleWithPath:@“ItemA”而不是“mainBundle”,但这不起作用。