簡體   English   中英

如何設置UITableViewRowAction的動作

[英]How to set the action of UITableViewRowAction

我自定義了UITableCellDeleteConfirmationView以更改iOS 8及更高版本中按鈕的背景顏色。 在這篇文章之后 ,我實現了editActionsForRowAtIndexPathcommitEditingStylecanEditRowAtIndexPath

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

    RankedSpecies* rankedSpecies = [fetchedResultsController objectAtIndexPath:indexPath];

    if ( [self.collectedLeaf.selectedSpecies isEqualToString:[rankedSpecies.Species commonNameFirstLast]] )
    {
        UITableViewRowAction *unlabelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"UnLabel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                        {
                                             NSLog(@"Action to perform with Button 1");
                                        }];
        unlabelSpecies.backgroundColor = [UIColor darkGrayColor];

        return @[unlabelSpecies];
    }

    UITableViewRowAction *labelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Label" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                    {
                                        NSLog(@"Action to perform with Button 1");
                                    }];
    labelSpecies.backgroundColor = [UIColor darkGrayColor];

    return @[labelSpecies];
}

但是,當我按下這些自定義按鈕時,它們不會調用commitEditingStyle 根據這篇文章 ,只有當您點擊刪除按鈕時,才會觸發commitEditingStyle

我沒有嘗試找出如何觸發commitEditingStyle方法,而是創建了復制我的commitEditingStyle實現的方法removeCollectedLeafLabel 類方法可以作為動作嗎? 按下時如何設置UITableViewRowAction以執行某些操作?

當您按下按鈕時,它將調用該塊。

UITableViewRowAction *unlabelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"UnLabel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                        {
                                             CALL_YOUR_METHOD_FROM_HERE
                                        }];


unlabelSpecies.backgroundColor = [UIColor darkGrayColor];

return @[unlabelSpecies];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM