viewForHeaderInSection中的UISwipeGestureRecognizer

时间:2013-06-17 15:22:24

标签: ios uitableview uiswipegesturerecognizer

我正在尝试仅向表格标题添加滑动左侧识别。 似乎没有工作 - 尝试在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;

}

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

感谢您的帮助

1 个答案:

答案 0 :(得分: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

{     返回YES; }

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

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

@interface TableViewController : UIViewController<UIGestureRecognizerDelegate>