我在
中创建了一个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/