我在文檔文件夾中創建plist文件,我想在NSDictionary中調用和存儲數據,但我不知道使用什麼語法?如何調用文檔文件夾中的plist文件
我的plist文件是字典型。
這是我的代碼:
#define DOC_DIR [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
NSString *item = @"Content";
array = [[NSMutableArray alloc]init];
for (int i =0; i<8; i++) {
[array addObject:item];
}
NSLog(@"array : %@",array);
[self WriteDataToPlistFromArray:array];
- (void)WriteDataToPlistFromArray:(NSArray*)dataArray
{
NSDictionary *dic = [NSMutableDictionary dictionaryWithObjectsAndKeys:dataArray,@"Root", nil];
NSString *Path = [DOC_DIR stringByAppendingPathComponent:@"mamal.plist"];
[dic writeToFile:Path atomically:YES];
NSLog(@"%@",dic);
NSLog(@"%@",Path);
}
I want call plist from Document Folder and show data in it.
我的朋友這段代碼從mamal.plist中讀取數據?在哪寫這個代碼? – fred 2013-04-24 07:49:14
當您需要plist的數據時,請寫下此代碼。任何地方你可以用它來檢索數據 – 2013-04-24 07:51:37
我的朋友我把這個代碼放在一個名稱爲(ReadDataFromPlist)的函數中,並使用代碼[self ReadDataFromPlist]從viewDidLoad中調用此函數,但字典爲空。 – fred 2013-04-24 07:57:31