从Nsdocument目录中删除数据

时间:2013-01-12 12:52:55

标签: iphone ios objective-c cocoa-touch

如何使用以下代码删除我保存的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];

2 个答案:

答案 0 :(得分:2)

试试这个:

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

NSString *documentsDirectory = [paths objectAtIndex:0]; 

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

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

答案 1 :(得分:1)

试试这个,

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