Ios6 无法在iOS中删除PDF文件

Ios6 无法在iOS中删除PDF文件,ios6,nsfilemanager,nsdocumentdirectory,Ios6,Nsfilemanager,Nsdocumentdirectory,我正在通过以下链接创建PDF页面 http://mobile.tutsplus.com/tutorials/iphone/generating-pdf-documents/?search_index=3 我无法使用以下方法删除此PDF文件。我已经评论了错误行 self.fileMgr = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirecto

我正在通过以下链接创建PDF页面

http://mobile.tutsplus.com/tutorials/iphone/generating-pdf-documents/?search_index=3
我无法使用以下方法删除此PDF文件。我已经评论了错误行

self.fileMgr = [NSFileManager defaultManager];

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
 NSString *documentsDirectory = [paths objectAtIndex:0];

 NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.pdf",[self.tablePdfListArray objectAtIndex:indexPath.row]]];

 if([self.fileMgr fileExistsAtPath:pdfPath] == YES)
 {

 [fileMgr removeFileAtPath: pdfPath error:nil];  //No visible @interface for NSFilemanager declares the selector removeFileAtPath 
 }
你能建议一下吗。提前感谢。

在NSFileManager的类引用中,我找不到removeFileAtPath:error:method。这似乎是一个非常古老的实例方法。有一个类似的方法removeFileAtPath:handler:似乎已被弃用

请尝试改用removitematpath:error:命令。从:

removitematpath:错误:

删除指定路径处的文件或目录

你应该熟悉这个用法。我建议您将error param分配给NSError变量,以便在操作结束时检查NSError,以防万一:

NSError *error = nil;
BOOL deleted = [[NSFileManager defaultManager] removeItemAtPath:pdfPath error:&error];
if (!deleted) {
    NSLog(@"Unable to delete pdf at %@, reason: %@", path, error);
}

在插入removeFileAtPath之前,我应用了与您建议的相同的方法。那一次,removeItemAtPath不起作用。我想知道它今天工作得怎么样。感谢您的回答:)NSLog is给我这个错误域=NSCOCAERRORDOMAIN Code=4“操作无法完成。(Cocoa错误4.)“UserInfo=0x1f504530{NSUnderlyingError=0x1f52efc0”操作无法完成。没有这样的文件或目录”,NSFilePath=/var/mobile/Applications/8A4C9907-541C-4186-AE79-92772BEBCB16/Documents/so.pdf,NSUserStringVariant=(删除)}。文件正在被删除。@NavnathMemane因此文件已被删除,但仍有错误消息?是。通过删除tableview行数组,pdf文件将被删除。我无法通过在tableView数组中创建相同的名称(以前已删除)来访问PDF文件。真的越来越少了吗?如何交叉检查?@NavnathMemane您需要检查您的模拟器路径,如上面的错误消息所述。