0

リンクをたどって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 
 }

提案していただけませんか。前もって感謝します。

4

1 に答える 1

0

NSFileManager のクラス参照のどこにもremoveFileAtPath:error:メソッドが見つかりません。非常に古いインスタンス メソッドのようです。非推奨と思われる同様のメソッドremoveFileAtPath:handler:があります。

代わりにremoveItemAtPath:error:を使用してみてください。NSFileManagerのクラス参照から:

removeItemAtPath:エラー:

指定されたパスにあるファイルまたはディレクトリを削除します。

使用法に精通している必要があります。念のため、操作の最後に NSError を確認できるように、エラー パラメータを NSError 変数に割り当てることをお勧めします。

NSError *error = nil;
BOOL deleted = [[NSFileManager defaultManager] removeItemAtPath:pdfPath error:&error];
if (!deleted) {
    NSLog(@"Unable to delete pdf at %@, reason: %@", path, error);
}
于 2013-06-06T14:48:06.900 に答える