首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何设置UITableViewRowAction的动作

如何设置UITableViewRowAction的动作
EN

Stack Overflow用户
提问于 2017-09-28 20:21:57
回答 1查看 249关注 0票数 0

我定制了我的UITableCellDeleteConfirmationView以更改iOS 8和更高版本中按钮的背景色。Following this post,我实现了editActionsForRowAtIndexPathcommitEditingStylecanEditRowAtIndexPath

代码语言:javascript
复制
-(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设置为按下某些操作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-09-28 20:33:12

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

代码语言:javascript
复制
UITableViewRowAction *unlabelSpecies = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"UnLabel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                        {
                                             CALL_YOUR_METHOD_FROM_HERE
                                        }];


unlabelSpecies.backgroundColor = [UIColor darkGrayColor];

return @[unlabelSpecies];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46477676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档