2012-02-22 17 views
0

對於iPhone應用程序開發,我還是相當新的,我需要你的幫助。我正嘗試用我自己的圖像填充Apple的PhotoScroller example中的imageData.plist,請你指導我如何基於全圖像文件夾中的所有圖像以編程方式填充此plist文件?我面臨的另一個挑戰是任何時候都可以在文件夾中放置任意數量的未知圖像。以下是plist文件的快照。 plist中表在PhotoScroller示例中填充ImageData.plist

定義

 
Item 0 Dictionary (3 items)
height Number 400
width Number 290
name string Lake
Item 1 Dictionary (3 items)
height Number 400
width Number 290
name string Tree
Item 2 Dictionary (3 items)
height Number 400
width Number 290
name string Shed
Item 3 Dictionary (3 items)
height Number 400
width Number 290
name string Rock

我知道,我必須使用NSDictionary中類和將writeToFile實現這一目標,但如何去了解這一點,我需要幫助。

回答

0

一組NSDictionarys?

NSMutableArray *dicts = [NSMutableArray arrayWithCapacity:10]; 
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:400], @"height", [NSNumber numberWithInt:290], @"width", @"Lake", @"name", nil]; 
[dicts addObject:dict]; 
//and so on... 

NSFileManager *fileManager = [NSFileManager defaultManager]; 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"filename.plist"]; 

[dicts writeToFile:filePath atomically:YES];