I am working with UITableViewRowAction. My requirement is that on left swipe of a table cell, I should show 2 UITableViewRowAction button
. I am able to achieve that by implementing -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath;
. Here is the code for that
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button 1");
}];
button.backgroundColor = [UIColor greenColor]; //arbitrary color
UITableViewRowAction *button2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
{
NSLog(@"Action to perform with Button2!");
}];
button2.backgroundColor = [UIColor redColor]; //arbitrary color
return @[button, button2];
}
Currently I am using some arbitrary color as background for button
and button2
.
But my requirement is to have a background image instead of some color. I went through the answer given here and tried and implemented it by adding
button.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"icon_ab_delete.png"]];
instead of
button.backgroundColor = [UIColor greenColor];
I have icon_ab_delete.png stored in my project. But, when I run my app I get a white color background with nothing on it. Something like this:
The button after edit which was suppose to be for delete shows nothing, and it does exist as I can still capture the event I am trying to do inside it's handler.
I want to know whether I am setting the background image correctly or is there some other way to do what I am trying to achieve?
Thanks in advance!