0

我正在尝试仅向表格标题添加向左滑动识别。似乎不起作用 - 尝试了在 stackoverflow 和 web 上找到的所有内容。在实际的表格单元格上工作正常,但将其添加到表格标题时......什么都没有。

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

}

它只是不会滑动,我尝试在桌子上添加手势等......

谢谢您的帮助

4

1 回答 1

0

好的,让这该死的东西起作用了,这就是诀窍

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

并且必须添加2个功能:

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

{返回是;}

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

当然在 .h 文件中添加委托

@interface TableViewController : UIViewController<UIGestureRecognizerDelegate>
于 2013-06-17T16:31:41.893 回答