简体   繁体   English

如何捕获按TabViewCell的事件?

[英]How to catch event of pressing TableViewCell?

I have question for you ... I have UITableView and I want to catch event when user press the cell in order to change the color of label that I insert into UITableViewCell. 我有问题...我有UITableView,我想在用户按下单元格时捕获事件,以便更改我插入UITableViewCell的标签颜色。 The moment when user touch the cell. 用户触摸单元格的那一刻。

  1. tableView:willSelectRowAtIndexPath: 的tableView:willSelectRowAtIndexPath:
  2. tableView:didSelectRowAtIndexPath: 的tableView:didSelectRowAtIndexPath方法:

functions didn't help me ... 功能对我没有帮助......

Who have any suggestion ? 谁有任何建议? Thanks a lot for help !!! 非常感谢你的帮助!

Subclass the UITableViewCell and override the UIResponder with these: 对UITableViewCell进行子类化并使用以下方法覆盖UIResponder:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;

Then you will have 2 separated events when press and when release. 然后,当按下和释放时,您将有2个独立的事件。

If you want to change the color of a UILabel inside a UITableViewCell when it's selected, you don't have to do any sort of event catching. 如果要在UITableViewCell选中时更改UILabel内部的颜色,则不必执行任何类型的事件捕获。 You just have to change the highlightedTextColor property of the UILabel . 您只需要更改UILabelhighlightedTextColor属性。 The default is usually white. 默认值通常为白色。

Did you set the delegate of the tableView? 你设置了tableView的委托吗?

Did your class conform to the UITableViewDelegate protocol? 您的类是否符合UITableViewDelegate协议?

Confirm With UITableViewDelegate protocol and implement the methods which you mention, 使用UITableViewDelegate协议确认并实现您提到的方法,

Do'nt forget to set the delegate property of your UITableView . 不要忘记设置UITableView的委托属性。

myTableView.delegate = self;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM