0

I created an instance of UITableViewRowAction in

 -(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:

 [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.

Any idea how I can change the backgroundColor while the row actions are still visible? Thanks

  • xCoder
stevekohls
  • 2,214
  • 23
  • 29
Janosch Hübner
  • 1,584
  • 25
  • 44

1 Answers1

2

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];
}
Nishant
  • 12,529
  • 9
  • 59
  • 94