简体   繁体   中英

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. The moment when user touch the cell.

  1. tableView:willSelectRowAtIndexPath:
  2. 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:

- (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.

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. You just have to change the highlightedTextColor property of the UILabel . The default is usually white.

Did you set the delegate of the tableView?

Did your class conform to the UITableViewDelegate protocol?

Confirm With UITableViewDelegate protocol and implement the methods which you mention,

Do'nt forget to set the delegate property of your UITableView .

myTableView.delegate = self;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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