[英]UISwipeGestureRecognizer in viewForHeaderInSection
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. 似乎不起作用-尝试了在stackoverflow和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; {SnapSong * song = nil;
NSString *text = song.title; NSString *文本= song.title; NSString *detailedText = song.albumName; 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: 并且必须添加2个功能:
-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{ return YES; {返回是; } }
And of course in the .h file add the delegate 当然,在.h文件中添加委托
@interface TableViewController : UIViewController<UIGestureRecognizerDelegate>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.