简体   繁体   English

UITableViewRowAction更改背景颜色

[英]UITableViewRowAction change backgroundcolor on press

I created an instance of UITableViewRowAction in 我在创建了UITableViewRowAction的实例

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

and I have a handler block when this row action is triggered: 当触发该行操作时,我有一个处理程序块:

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

You have a row action parameter that can be used so you do not create retain cycles and you have an index path. 您具有可以使用的行操作参数,因此您不会创建保留周期,并且具有索引路径。 I've tried setting the backgroundColor of that new row action like this: 我试过像这样设置新行动作的backgroundColor

 [action setBackgroundColor:[UIColor greenColor]];

But this did not change anything. 但这并没有改变任何东西。 I also tried setNeedsDisplay on the button object of the row action, but without any luck. 我还在行操作的按钮对象上尝试了setNeedsDisplay ,但没有任何运气。

Any idea how I can change the backgroundColor while the row actions are still visible? 知道在行动作仍然可见的情况backgroundColor如何更改backgroundColor吗? Thanks 谢谢

  • xCoder xCoder

Here is my implementation of the same and it works well. 这是我的相同实现,效果很好。 It should solve your problem as well.. 它也应该解决您的问题。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM