2015-12-09 78 views

回答

1

嘗試電話:

cell.selectionStyle = UITableViewCellSelectionStyleNone 
cellForRowAtIndexPath

和(可選)重寫:

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 

迅速:

override func setSelected(selected: Bool, animated: Bool) 

斯威夫特用法示例:

override func setSelected(selected: Bool, animated: Bool) { 
    if selected { 
     yourView.alpha = 0.5 
    } else { 
     yourView.alpha = 1.0 
    } 
} 

你也可以改變內部animateWithDuration擋住你的視線的阿爾法:

override func setSelected(selected: Bool, animated: Bool) { 
    UIView.animateWithDuration(0.3, animations: { 
     if selected { 
      yourView.alpha = 0.5 
     } else { 
      yourView.alpha = 1.0 
     } 
    }) 
} 

對象 -用法示例:

#import "YourTableViewCell.h" 

@implementation YourTableViewCell 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated { 
    [super setSelected:selected animated:animated]; 
    //your code 
    // example: yourView.backgroundColor = [UIColor greenColor]; 
} 

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 
    [super setHighlighted:highlighted animated:YES]; 
    //your code 
    // example: yourView.backgroundColor = [UIColor greenColor]; 
} 

@end 
+0

如何以及在哪裏呼叫setSelected? –

+0

正如你所看到的,在函數聲明之前有'override'關鍵字。你不必調用它。 UITableView會爲你調用它。只要將這個方法放在你的UITableViewCell子類中。 – zuziaka

+0

我使用objc代碼沒有覆蓋 –

0

您可以更改單元格的ImageView在你UITableView

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
      //get the cell from the selected row. 
      UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath]; 

     //change custom cell's imageView to desired backgroundColor 
     selectedCell.imageView = [UIColor clearColor]; 
} 

-didSelectRowAtIndexPath而且不要忘記實現UITableViewDelegateUITableViewDatasource

0

我想可能是發生由於tableviewcell選擇。 只需使用下面的代碼片斷

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
    [tableview deselectRowAtIndexPath:indexPath animated:YES]; 
} 

這可以幫助你。如果沒有,那麼請分享您的實施信息。

0

你可能已經設置圖像視圖的背景色清除顏色。

相關問題