UITableView controls what happens when selected

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

I know that in iOS 6.0 this is possible like this:

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

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

+4
source share
3 answers

If you have a custom UITableViewCell, you can override

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

which will be called when the cell is touch-sensitive (the highlighted parameter will be YES), and when the touch is raised or canceled (the highlight parameter is NO).

Also this approach will work on iOS 3.0 and later.

+2
source

The best option for iOS 5 would be to use this method.

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

Although this method is only called when the user clicks and then removes his finger from the cell (as explained here ), I’m not learning about any other methods available in both 5.x and 6.x that you could use for this.

+3
source

In one of my projects, I needed to highlight my image by immediately touching the camera, so I implemented the backlight state in Ios 5.0 like this. These functions are written to the custom cell class. Change these features to suit your requirements.

  -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self hightlightImage]; [self performSelector:@selector(detecetedLongTap) withObject:nil afterDelay:1.0]; [super touchesBegan:touches withEvent:event]; } -(void)detecetedLongTap{ [self hightlightImage]; } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { [super touchesMoved:touches withEvent:event]; } -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { if (titleLabel.textColor == [UIColor blackColor]) [self hightlightImage]; [super touchesEnded:touches withEvent:event]; } 
+2
source

Source: https://habr.com/ru/post/1481158/


All Articles