我複製的plist文件來讀取目錄時didFinishLaunchingWithOptions在AppDelegate中是這樣的:複製的plist到文檔目錄,並從中
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self performSelector:@selector(copyPlist)];
return YES;
}
- (void)copyPlist {
NSFileManager *fileManger=[NSFileManager defaultManager];
NSError *error;
NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
NSString *doumentDirectoryPath=[pathsArray objectAtIndex:0];
NSString *destinationPath= [doumentDirectoryPath stringByAppendingPathComponent:@"Obj.plist"];
if ([fileManger fileExistsAtPath:destinationPath]){
NSLog(@"database localtion %@",destinationPath);
return;
}
NSString *sourcePath=[[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"Obj.plist"];
[fileManger copyItemAtPath:sourcePath toPath:destinationPath error:&error];
}
然後我想顯示的plist在我的意見內容像這樣:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Obj.plist"];
NSLog(@"plist path %@", path);
sortedObj = [[NSMutableArray alloc]initWithContentsOfFile:path];
NSLog(@"objects %@", sortedObj);
日誌結果:
數據庫當前位置:
/Users/kdb/Library/Application Support/iPhone Simulator/5.1/Applications/4E165740-01CD-4ED3-8971-FDCCB1751DD1/Documents/Obj.plist
的plist路徑:
相同數據庫位置
對象:
(空)
內容是空的。 如何使它工作?
plist是一個有字典的數組。
.plist文件的結構怎麼樣?可能是頂級對象不是NSArray(),而是NSDictionary()。你也可以在你的問題中包括你的plist的前幾行嗎? –
gschandler
2012-08-11 18:33:48
plist是一個包含字典的數組,例如:array,dict,key,string,key,string,/ dict,dict,key,string,key,string,/ dict,/ array – ingenspor 2012-08-11 18:38:26
你是否在刪除內容?你可以在模擬器中檢查嗎? – 2012-08-11 18:45:27