2017-09-22 9 views
0

プログラミングが初めてです。次のコードはスワイプで行を削除しても機能しますが、すべての行のリストが更新された後に表示されます。 私は、次のしているコード:UItableviewスワイプの削除iOS 11でデータを更新/再読み込みしません。

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive 
                     title:@"DELETE" 
                     handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { 
                      NSLog(@"index path of delete: %@", indexPath); 
                      completionHandler(YES); 


                     }]; 
    delete.backgroundColor = [UIColor purpleColor]; //arbitrary color 

    UISwipeActionsConfiguration *swipeActionConfig = [UISwipeActionsConfiguration configurationWithActions:@[delete]]; 
    swipeActionConfig.performsFirstActionWithFullSwipe = NO; 

    return swipeActionConfig; 

} 

私は、次の使用しています:completionHandlerで

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    FCell = (favouriteCell *)[tableView dequeueReusableCellWithIdentifier:@"favouriteCell"]; 
    FCell.selectionStyle=UITableViewCellSelectionStyleNone; 
    if (FCell == nil) 
    { 
     FCell = [[[NSBundle mainBundle]loadNibNamed:@"favouriteCell" owner:nil options:nil] objectAtIndex:0]; 
    } 

    FCell.nameLBL.text=[[favDetails objectAtIndex:indexPath.row] valueForKey:@"name"]; 
    FCell.poetLBL.text=[[favDetails objectAtIndex:indexPath.row] valueForKey:@"poet"]; 
    return FCell; 

} 
+0

データソースから行を削除しているようではありません。 削除のインデックスパスを記録するcompletionHandlerでは、データソース(配列など)からその行を削除する必要があります。そうしないと、テーブルがデータソースからリロードされたときに再び表示されます。 – Stephen

+0

ありがとう、それを行う最良の方法は何でしょうか? – Simi

+0

データソースとしてどのような構造を使用していますか? cellForRowAtIndexPathからいくつかのコードを共有できますか? – Stephen

答えて

0

あなたが削除のインデックスパスをログに記録されている場合、あなたはあなたのデータソースからその行を削除する必要があります(配列など)。そうしないと、テーブルがデータソースからリロードされたときに再び表示されます。

あなたtrailingSwipeActionsConfigurationForRowAtIndexPathコードは次のようになります。

- (UISwipeActionsConfiguration *)tableView:(UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath { 
     UIContextualAction *delete = [UIContextualAction contextualActionWithStyle:UIContextualActionStyleDestructive 
                      title:@"DELETE" 
                      handler:^(UIContextualAction * _Nonnull action, __kindof UIView * _Nonnull sourceView, void (^ _Nonnull completionHandler)(BOOL)) { 
                       NSLog(@"index path of delete: %@", indexPath); 
[favDetails removeObjectAtIndex:indexPath.row];             
completionHandler(YES); 


                      }]; 
     delete.backgroundColor = [UIColor purpleColor]; //arbitrary color 

     UISwipeActionsConfiguration *swipeActionConfig = [UISwipeActionsConfiguration configurationWithActions:@[delete]]; 
     swipeActionConfig.performsFirstActionWithFullSwipe = NO; 

     return swipeActionConfig; 

    } 

行がテーブルから視覚的に除去される。これは、データソースからオブジェクトを削除します。

+0

多くのことに感謝しますが、エラーが表示されます。私は私の質問にNSlogのコードを追加しました。 – Simi

+0

あなたの質問の新しいコードがオリジナルとどのように関連しているか分かりません。私の答えはあなたの元の質問を解決すると信じています。 あなたはおそらくあなたのエラーで新しい質問を開くべきです。 – Stephen

+0

私は明確にするために私の答えを編集しました。 – Stephen

関連する問題