-1
ストーリーボードを使用してバーボタンアイテム(ゴミ箱)を作成します.Appは、ボタンアクションでドキュメントディレクトリからファイルを削除しようとするとクラッシュします。私はあなたが次のコードで最初のファイルがパスに存在するかどうかをチェックすべきだと思うobjective-cを使用してbarボタン項目を使用してドキュメントディレクトリからファイルを削除するにはどうすればよいですか?
@property (retain, nonatomic) IBOutlet UIBarButtonItem *deleteCsv;
-(void)deleteCsv:(id)sender{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:fileDataString4];
NSError *error;
BOOL success = [fileManager removeItemAtPath:filePath error:&error];
if (success) {
UIAlertView *removedSuccessFullyAlert = [[UIAlertView alloc] initWithTitle:@"Congratulations:" message:@"Successfully removed" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:nil];
[removedSuccessFullyAlert show];
}
else
{
NSLog(@"Could not delete file -:%@ ",[error localizedDescription]);
}
クラッシュやエラーに関する質問を投稿するときは、質問に以下を含める必要があります(質問を編集する、コメントを投稿しないでください):1 - 完全で正確なエラーメッセージ。 2 - エラーを引き起こすコードの正確な行を指摘してください。 – rmaddy
@Alivajorg fileDataString4とは何ですか? – aNa12
削除したいファイルの文字列が入っています@ aNa12 – Alivajorg