Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView control what happens when highlighted

I want to control what happens in my UITableViewCell when it is highlighted.

I know it is possible in iOS 6.0 like so:

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath

But how I do it if I am targeting 5.0 and above?

like image 837
WYS Avatar asked Mar 23 '23 22:03

WYS


2 Answers

Your best option on iOS 5 would be to use this method

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

Though this method is called only when the user taps and then lifts their finger off the cell (as explained here), but I am not aware of any other methods available in both 5.x and 6.x which you could use for this.

like image 163
lostInTransit Avatar answered Apr 02 '23 19:04

lostInTransit


If you have a custom UITableViewCell you can override the

-(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated

method which will be called when the touch is down on the cell (the highlightedparam will be YES) and when the touch is up or canceled(the highlight parameter is NO).

Also this approach will work on iOS 3.0 and later.

like image 29
danypata Avatar answered Apr 02 '23 18:04

danypata