2016-11-28 2 views
-1

テーブルビューを使用してファイルをリストしています。それは完璧に動作します。しかし、削除のために左にスワイプすると、テーブルビューは編集モードになり、編集ボタンはキャンセルボタンで上書きされます。それも完璧です。しかし、削除せずにスワイプすると、ボタンが編集に戻るはずですが、それは起こりません。テーブルビューのセルをスワイプしたときに呼び出されるデリゲートはありますか?これは、関連するコードテーブルビューのセルを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のコードです:事前

+0

コードを投稿する方が良いでしょう。 –

+0

@ ArpitDongre –

+0

@ManeeshSharma:私たちには、UITableView関連のコードが必要です。 – Poles

答えて

1

if ([[[NSUserDefaults standardUserDefaults] objectForKey:DOCUMENTDELETE] isEqualToString:ENABLED]) { 
    if (self.tableView.editing){ 
     self.navigationItem.rightBarButtonItem = nil; 
     self.navigationItem.rightBarButtonItem = self.cancelButton; 
    }else { 
    self.navigationItem.rightBarButtonItem = nil; 
[self.navigationItem setRightBarButtonItem:self.editButton]; 
    }} else { 
     self.navigationItem.rightBarButtonItem = nil; 
    } 

おかげであなたは、単にデリゲートメソッド

tableView:didEndEditingRowAtIndexPath:

を実装する必要があるようですね

あなたがキャッチする場所ですテーブルビューセルは編集状態から未設定である。

+0

それは完璧に働いた!ちょうど私が欲しかったことです。ありがとう –

関連する問題