在按下状态和选择状态时更改UITableViewCell的颜色

Akb*_*ali 2 iphone uitableview android-selector

我正在使用带有customCell的UITableView(CustomCell有2个标签和一个ImageView).

在正常模式下,我需要所有细胞的白色.

如果用户按下特定单元格,则该单元格的颜色应为灰色(其余单元格应为白色)

如果用户释放相同的单元格,该单元格的颜色应为橙色(其余单元格应为白色)

我怎么能搞清楚?

我已经尝试使用setSelectedBackground,willSelectRowAtIndexPath和Gestures方法.但无法看到同一Cell的这3种颜色状态.这两个州中的任何一个都在一起工作.

任何想法我怎样才能实现相同的功能?

我使用选择器在android中实现了相同的功能.我想在iPhone中使用相同的功能.任何帮助?

提前致谢!

Ani*_*ari 7

在自定义单元格中写下这两种方法

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    self.contentView.backgroundColor=[UIColor greenColor];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
    self.contentView.backgroundColor=[UIColor orangeColor];

}
Run Code Online (Sandbox Code Playgroud)

  • @AkbariDipali您可能需要调用[super touchesEnded:touches withEvent:event] (4认同)