Is it possible to make a UITableViewCell
high-lite when a finger passes over it? Not just when it pushes down on it, but when the finger is already sliding across the screen and runs over the tableviewcell? I've tried all of the gesture recognizers (including UILongPressGestureRecognizer
) and haven't had any luck.
Asked
Active
Viewed 93 times
0

Ser Pounce
- 14,196
- 18
- 84
- 169
-
Gesture recognizer on the superview that detects what subviews are under the current location of the touch? – Hunter Oct 10 '12 at 01:16
-
Have a look at responses to this question: http://stackoverflow.com/questions/6286230/touches-began-in-uitableviewcontroller (particularly last one) might provide some insight. – gamozzii Oct 10 '12 at 01:28
2 Answers
1
Try using this function, its similar to the one in the question mentioned in the comments:
(in your viewController)
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
//assuming UITableView named tableView
UITableViewCell *tableViewCell;
CGPoint touchedPoint = [[touches anyObject] locationInView:self.view];
for (int C = 0; C < [tableView numberOfRowsInSection:0]; C++) {
//this should loop through all cells in your tableview
tableViewCell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathWithIndex:C]];
if (CGRectContainsPoint(tableViewCell.frame, touchedPoint)) {
[tableViewCell setHighlighted:TRUE];
}
else {
[tableViewCell setHighlighted:FALSE];
}
}
}

WolfLink
- 3,308
- 2
- 26
- 44
0
in cellForRowAtIndexPath:
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipe:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[cell.contentView addGestureRecognizer:recognizer];
then...
- (void)handleSwipe:(id)sender
{
UISwipeGestureRecognizer *recognizer = (UISwipeGestureRecognizer *)sender;
UIView *contentView = [recognizer view];
UITableViewCell *cell = (UITableViewCell*)[contentView superview];
[cell setSelected:YES];
}
I just tested this and it works exactly like what you are looking for.
EDIT: If I weren't in a rush, I would have done some introspection before type casting.

geraldWilliam
- 4,123
- 1
- 23
- 35