2016-08-24 43 views
2

我在我的源代碼3 UITableViewRowAction's,象下面這樣:UITableViewRowAction - 酮的背景顏色影響其它

- (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條件,被禁用。

但是,messageActionbackgroundColor影響另外兩個時,只有啓用和其他兩個被禁用。

爲了確認這一點,我將cancelAction作爲第一個來顛倒按鈕的顯示順序。這樣,取消按鈕的backgroundColor影響了其他兩個。

如何修復每個按鈕的可視化屬性backgroundColor屬性?

+0

想要的行爲是什麼?它不清楚 – ddb

+0

@ddb:期望的行爲是當他們沒有權限時,顯示禁用形式的按鈕(通過減少其背景)。 – Nitish

+0

@ddb:但如果它只是一個對象,那麼如何顯示3個不同的按鈕? – Nitish

回答

0

覆蓋的editActionsForRowAtIndexPath的tableview代表如下方法: -

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewRowAction *messageButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Message" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
            { 
             NSLog(@"Action to perform with messageButton Button"); 
            }]; 
    UIColor *messageColor = if(messagePremission == true) ? [UIColor colorWithRed:82.0/255.0 green:82.0/255.0 blue:82.0/255.0 alpha:1.0] : 
     [UIColor colorWithRed:200.0/255.0 green:199.0/255.0 blue:205.0/255.0 alpha:0.1]; 
    messageButton.backgroundColor = messageColor; 

    UITableViewRowAction *editButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Edit" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
            { 
             NSLog(@"Action to perform with editButton Button!"); 
            }]; 
    UIColor *editColor = if(editPermission == true) ? [UIColor colorWithRed:2.0/255.0 green:118.0/255.0 blue:246.0/255.0 alpha:1.0] : 
     [UIColor colorWithRed:2.0/255.0 green:118.0/255.0 blue:246.0/255.0 alpha:0.1]; 
    editButton.backgroundColor = editColor; 

    UITableViewRowAction *cancelButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Cancel" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) 
            { 
             NSLog(@"Action to perform with cancelButton"); 
            }]; 
    UIColor *cancelColor = if(cancelPermission == true) ? [UIColor colorWithRed:251.0/255.0 green:1.0/255.0 blue:13.0/255.0 alpha:1.0] : 
     [UIColor colorWithRed:251.0/255.0 green:1.0/255.0 blue:13.0/255.0 alpha:0.1]; 
    cancelButton.backgroundColor = cancelColor; 

    return @[messageButton, editButton, cancelButton]; 
} 
0

你的背景顏色具有α值 - 該動作視圖從最右邊的按鈕繪製彼此的頂部之上向內。

使用沒有alpha的顏色,它應該很好,並且不會與其他按鈕背景顏色混合。