【发布时间】:2016-08-24 10:49:59
【问题描述】:
我的源代码中有 3 个UITableViewRowAction's,如下所示:
- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView
editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(messagePremission)
{
messageAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:[NSString stringWithFormat:@"%@%@", NSLocalizedString(@"message_admin", nil), activity.GroupName] handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
messageAction.backgroundColor = [UIColor colorWithRed:82.0/255.0 green:82.0/255.0 blue:82.0/255.0 alpha:1.0];
}
else
{
messageAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:[NSString stringWithFormat:@"%@%@", NSLocalizedString(@"message_admin", nil), activity.GroupName] handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
messageAction.backgroundColor = [UIColor colorWithRed:200.0/255.0 green:199.0/255.0 blue:205.0/255.0 alpha:0.1];
}
if(editPermission)
{
editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:NSLocalizedString(@"edit_swipe", nil) handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
editAction.backgroundColor = [UIColor colorWithRed:2.0/255.0 green:118.0/255.0 blue:246.0/255.0 alpha:1.0];
}
else
{
editAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:NSLocalizedString(@"edit_swipe", nil) handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
editAction.backgroundColor = [UIColor colorWithRed:2.0/255.0 green:118.0/255.0 blue:246.0/255.0 alpha:0.1];
}
if(cancelPermission)
{
cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Cancel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
cancelAction.backgroundColor = [UIColor colorWithRed:251.0/255.0 green:1.0/255.0 blue:13.0/255.0 alpha:1.0];
}
else
{
cancelAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Cancel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
}];
cancelAction.backgroundColor = [UIColor colorWithRed:251.0/255.0 green:1.0/255.0 blue:13.0/255.0 alpha:0.1];
}
[arrButtons addObject:messageAction];
[arrButtons addObject:editAction];
[arrButtons addObject:cancelAction];
return arrButtons;
}
在每个if 条件下,按钮被创建为启用,而在各自的else 条件下,按钮被禁用。
但是,当仅启用 messageAction 而禁用其他两个时,messageAction 的 backgroundColor 会影响其他两个。
为了确认这一点,我颠倒了按钮的显示顺序,将cancelAction 放在首位。这样,取消按钮的backgroundColor 会影响其他两个。
如何修复每个按钮的可视化 od backgroundColor 属性?
【问题讨论】:
-
期望的行为是什么?不清楚
-
@ddb :期望的行为是在没有权限时以禁用的形式显示按钮(通过点亮它们的背景)。
-
@ddb : 但如果它只是一个对象,那么你建议如何显示 3 个不同的按钮?
-
@ddb : 你删除了你的答案!!
-
是的,这是不正确的,最后我会写一个新的;)对不起,但我不想收到一票否决
标签: ios objective-c uitableview uitableviewrowaction