I'm trying to add swipe left recognition to the table headers only. Doesn't seem to work- tried everything found on stackoverflow and web. Works fine on the actual table cells, but when adding it to the table headers... nothing.

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

{ SnapSong *song = nil;
NSString *text = song.title; NSString *detailedText = song.albumName;

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 80)];
view.backgroundColor = [[Globals sharedInstance] gCellBgColor];
view.tag = section;
UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                                 action:@selector(handleSwipeLeft:)];
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[view addGestureRecognizer:recognizer];

return view;

}

It just wouldn't swipe, I've tried adding gesture to the table etc...

Thanks for the help

有帮助吗?

解决方案

Ok, got the fricking thing working, this what did the trick

 UISwipeGestureRecognizer *recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
                                                                                 action:@selector(handleSwipeLeft:)];
**[recognizer setDelegate:self];**
[recognizer setDirection:(UISwipeGestureRecognizerDirectionLeft)];
[view addGestureRecognizer:recognizer];

and had to add 2 functions:

-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer

{ return YES; }

  • (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { return YES; }

And of course in the .h file add the delegate

@interface TableViewController : UIViewController<UIGestureRecognizerDelegate>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top