簡體   English   中英

從Nsdocument目錄中刪除數據

[英]Delete Data from Nsdocument Directory

如何使用以下代碼從NSDocumentDirectory中刪除已保存的數據。

 NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *fullFileName2 = [NSString stringWithFormat:@"%@nameArray", documentsDirectory];
 nameArray=[[NSMutableArray alloc]initWithContentsOfFile:fullFileName2];

 [nameArray addObject:nameField.text];
 [nameArray writeToFile:fullFileName2 atomically:NO];

嘗試這個 :

NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);  

NSString *documentsDirectory = [paths objectAtIndex:0]; 

NSString *fullFileName2 = [NSString stringWithFormat:@"%@nameArray", documentsDirectory]; 

[[NSFileManager defaultManager] removeItemAtPath:fullFileName2 error: NULL];    

嘗試這個,

 NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];
 NSString *fullFileName2 = [nameArray objectAtIndex:0];
 [[NSFileManager defaultManager] removeItemAtPath:fullFileName2 error: NULL];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM