ios - UITableViewRowAction 在按下时更改背景颜色

标签 ios objective-c uitableview uitableviewrowaction

我在

中创建了一个 UITableViewRowAction 的实例
 -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

当触发此行操作时,我有一个处理程序 block :

 handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)

您有一个可以使用的行操作参数,这样您就不会创建保留循环,并且您有一个索引路径。我试过像这样设置新行操作的 backgroundColor:

 [action setBackgroundColor:[UIColor greenColor]];

但这并没有改变什么。我还在行操作的按钮对象上尝试了 setNeedsDisplay,但没有任何运气。

知道如何在行操作仍然可见的情况下更改 backgroundColor 吗?谢谢

  • xCoder

最佳答案

这是我的实现,效果很好。它也应该可以解决您的问题..

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewRowAction *one = [UITableViewRowAction rowActionWithStyle:0 title:@"one" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

        NSLog(@"my first action");
    }];

    UITableViewRowAction *two = [UITableViewRowAction rowActionWithStyle:1 title:@"two" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

        NSLog(@"my second action");

    }];

    UITableViewRowAction *three = [UITableViewRowAction rowActionWithStyle:1 title:@"three" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {

        NSLog(@"my third action");
    }];

    one.backgroundColor = [UIColor purpleColor];
    two.backgroundColor = [UIColor greenColor];
    three.backgroundColor = [UIColor brownColor];

    return @[one, two, three];
}

关于ios - UITableViewRowAction 在按下时更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30529507/

相关文章:

ios - VALID_ARCHS = arm64 armv7 armv7s 不生成任何 armv7s

ios - PHPhotoLibrary requestAuthorization,不是请求

ios - UITableView 不显示自定义单元格的第二个实例

swift - 带有 UITapGestureRecognizer 的 UIView 通过拖动传递到它下面的 UITableView?

swift - 无效更新: invalid number of rows while using Realm

iphone - UItabBar 中的 PopOver

ios - Cocos2d 2.0 : vertices and sprites

iphone - 无法为目标进程配置泄漏工具

ios - 上传两张图片到WebServer

ios - Objective C iOS在圆弧上绘制矩形