2016-07-12 17 views
0

UITableviewにセルを左スワイプしたときに複数のオプションを表示するようにeditActionsForRowAtIndexPathを実装したいとします。だから私はこのコードを使用:editActionsForRowAtIndexPathアクションが消える

enter image description here

今日、私はこのようなeditActionsForRowAtIndexPath方法を変更することによって、viewTransアクションを排除することを決定した:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 
    //Obviously, if this returns no, the edit option won't even populate 
    return YES; 
} 

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 
    //Nothing gets called here if you invoke `tableView:editActionsForRowAtIndexPath:` according to Apple docs so just leave this method blank 
} 

-(NSArray *)tableview:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
            { 
             // Delete code here 
            }]; 

    UITableViewRowAction *changeAmt = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Amt" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
             { 
              // popover amount change code 
             }]; 

    changeAmt.backgroundColor = [UIColor colorWithRed:0.022 green:0.541 blue:0.001 alpha:1.00]; 


    UITableViewRowAction *changeAcct = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Acct" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
             { 
              // popover account change code 
             }]; 

    changeAcct.backgroundColor = [UIColor colorWithRed:1.000 green:0.492 blue:0.000 alpha:1.00]; 

    UITableViewRowAction *viewTrans = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"View" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
             { 
              // Push to view 
             }]; 
    viewTrans.backgroundColor = [UIColor colorWithRed:0.002 green:0.342 blue:0.710 alpha:1.00]; 


    return @[delete,changeAmt,changeAcct,viewTrans]; //array with the buttons delete, changeAmt, changeAcct, viewTrans 
} 

昨日、このコードは、この結果を生成しました:

-(NSArray *)tableview:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
            { 
             // Delete code here 
            }]; 

    UITableViewRowAction *changeAmt = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Amt" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
             { 
              // popover amount change code 
             }]; 

    changeAmt.backgroundColor = [UIColor colorWithRed:0.022 green:0.541 blue:0.001 alpha:1.00]; 


    UITableViewRowAction *changeAcct = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Acct" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
             { 
              // popover account change code 
             }]; 

    changeAcct.backgroundColor = [UIColor colorWithRed:1.000 green:0.492 blue:0.000 alpha:1.00]; 

// UITableViewRowAction *viewTrans = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"View" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
//          { 
//           // Push to view 
//          }]; 
// viewTrans.backgroundColor = [UIColor colorWithRed:0.002 green:0.342 blue:0.710 alpha:1.00]; 


    return @[delete,changeAmt,changeAcct]; //array with the buttons delete, changeAmt, changeAcct, viewTrans 
} 

enter image description here

だから私は、コードをコメント解除し、returnラインでviewTransアクションへの参照を置き換え:この変更されたコードは、デフォルトDeleteアクション以外のすべてのアクションが削除するの、何らかの形で、効果がありました。 追加のアクションは再表示されません。

これは私が修正した唯一のコードです。私が間違っていたことは誰にも分かりません。

答えて

0

私はあなたの質問に取り組んでいたと、当初、私はeditActionsForRowAtIndexPathメソッドが呼び出されることはできませんが、後に、私は少し問題を発見し、多分あなたのために同じである、方法

-(NSArray *)tableview:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 

の宣言正しい

- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 

ので、私の方法は、この

- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
            { 
             // Delete code here 
            }]; 

    UITableViewRowAction *changeAmt = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Amt" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
             { 
              // popover amount change code 
             }]; 

    changeAmt.backgroundColor = [UIColor colorWithRed:0.022 green:0.541 blue:0.001 alpha:1.00]; 


    UITableViewRowAction *changeAcct = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Acct" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
             { 
              // popover account change code 
             }]; 

    changeAcct.backgroundColor = [UIColor colorWithRed:1.000 green:0.492 blue:0.000 alpha:1.00]; 

    //UITableViewRowAction *viewTrans = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"View" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
    //         { 
              // Push to view 
    //         }]; 
    //viewTrans.backgroundColor = [UIColor colorWithRed:0.002 green:0.342 blue:0.710 alpha:1.00]; 


    return @[delete,changeAmt,changeAcct]; //array with the buttons delete, changeAmt, changeAcct, viewTrans 

} 
0のような滞在で、右ではありません

そして、これは私はこれがあなたに

+0

おかげで、Reinierを役に立てば幸い

enter image description here

をどのように見えるかです。私はこれにかなり新しいので、私は完全に理解していませんが、私はこのアプローチを検討します。 – rattletrap99