【问题标题】:How to set the action of UITableViewRowAction如何设置 UITableViewRowAction 的动作
【发布时间】:2017-09-28 20:21:57
【问题描述】:

我自定义了 UITableCellDeleteConfirmationView 以更改 iOS 8 及更高版本中按钮的背景颜色。 Following this post,我实现了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];
}

但是,当我按下这些自定义按钮时,它们不会调用 commitEditingStyleAccording to this post, commitEditingStyle 仅在您触摸删除按钮时触发。

我没有试图弄清楚如何触发commitEditingStyle,而是创建了复制我的commitEditingStyle 实现removeCollectedLeafLabel 的方法。 类方法可以是动作吗?如何设置 UITableViewRowAction 在按下时执行某些操作?

【问题讨论】:

    标签: ios objective-c uitableview uitableviewrowaction


    【解决方案1】:

    当您按下按钮时,它将调用该块。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多