【问题标题】:UITableViewRowAction change backgroundcolor on pressUITableViewRowAction 在按下时更改背景颜色
【发布时间】:2015-05-29 12:21:28
【问题描述】:

我在

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

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

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

您有一个可以使用的行操作参数,因此您不会创建保留周期,并且您有一个索引路径。我尝试像这样设置新行操作的backgroundColor

 [action setBackgroundColor:[UIColor greenColor]];

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

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

  • xCoder

【问题讨论】:

  • 在此处发布您的editActionsForRowAtIndexPath 工具

标签: ios objective-c uitableview uitableviewrowaction


【解决方案1】:

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

- (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];
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2019-04-14
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多