2012-09-20 37 views
0

在我的應用程序包中,我有幾個項目的幾個圖像。如何從mainBundle中的文件夾中將數字提取到數組?

ItemA_largepicture.png

ItemA_smallPicture.png

ItemA_overViewPicture.png

ItemB_largepicture.png

ItemB_smallPicture.png

ItemB_overViewPicture.png

它emC_largepicture.png

ItemC_smallPicture.png

ItemC_overViewPicture.png

...

我想提取,例如,所有ItemB圖片轉換成數組。我可以做王子建議

NSString *bundleRootPath = [[NSBundle mainBundle] bundlePath]; 
NSArray *bundleRootContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:bundleRootPath error:nil]; 
NSArray *files = [bundleRootContents filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self beginswith 'ItemB'"]]; 
NSLog(@"%@",files); 

這工作非常出色。接下來的問題是所有ItemB文件都位於名爲ItemB的文件夾中。不知何故,我需要在捆綁包中添加一個路徑到ItemB文件夾。我以爲

NSString *bundleRootPath = [[NSBundle bundleWithPath:@"ItemB"] bundlePath]; 

是合乎邏輯的,但這沒有奏效。 任何人都可以請解釋這是如何工作的,以及如何訪問該文件夾?

回答

1
NSString *bundleRootPath = [[NSBundle mainBundle] bundlePath]; 
NSString *itemBPath = [bundleRootPath stringByAppendingPathComponent:@"ItemB"]; 
NSArray *itemBContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:itemBPath error:nil]; 
相關問題