テーブルビューを使用してファイルをリストしています。それは完璧に動作します。しかし、削除のために左にスワイプすると、テーブルビューは編集モードになり、編集ボタンはキャンセルボタンで上書きされます。それも完璧です。しかし、削除せずにスワイプすると、ボタンが編集に戻るはずですが、それは起こりません。テーブルビューのセルをスワイプしたときに呼び出されるデリゲートはありますか?これは、関連するコードテーブルビューのセルをUITableIviewでスワイプしたときのアクションを設定します。
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if ([[[NSUserDefaults standardUserDefaults]objectForKey:DOCUMENTDELETE]isEqualToString:ENABLED]) {
return YES;
} else {
return NO;
}
}
-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView setEditing:NO];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView
editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if (self.tableView.editing) {
return UITableViewCellEditingStyleDelete;
}
else {
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = self.cancelButton;
return UITableViewCellEditingStyleDelete;
}
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
self.navigationItem.rightBarButtonItem = nil ;
self.navigationItem.rightBarButtonItem = self.editButton;
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSString *cellText;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
cellText = selectedCell.textLabel.text;
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *fileName =[NSString stringWithFormat:@"/Inbox/"];
NSString *allFilesPath = [documentsDirectory stringByAppendingPathComponent:fileName];
NSString *theactualFilePath = [allFilesPath stringByAppendingPathComponent:cellText];
NSError *error;
_success = [[NSFileManager defaultManager] removeItemAtPath:theactualFilePath error:&error];
[self.tableView setEditing:NO];
if ([_filePathsArray count] == 0) {
[[NSUserDefaults standardUserDefaults] setObject:DISABLED forKey:NOMATCHFOUND];
[[NSUserDefaults standardUserDefaults] setObject:@"1" forKey:ALLFILESDELETED];
[[NSUserDefaults standardUserDefaults]synchronize];
}
if (_success) {
}
else
{
NSLog(@"Could not delete file -:%@ ",[error localizedDescription]);
}
}
[self.tableView reloadData];
}
あり、これはのviewDidLoadのコードです:事前
コードを投稿する方が良いでしょう。 –
@ ArpitDongre –
@ManeeshSharma:私たちには、UITableView関連のコードが必要です。 – Poles