我附上一个UISwipeGestureRecognizer
到UITableViewCell
在cellForRowAtIndexPath:
方法,像这样:UIGestureRecognizer和UITableViewCell的问题
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UISwipeGestureRecognizer *gesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)];
gesture.direction = UISwipeGestureRecognizerDirectionRight;
[cell.contentView addGestureRecognizer:gesture];
[gesture release];
}
return cell;
}
然而,didSwipe
方法总是得到成功的刷卡叫了两声。我最初以为这是因为手势开始和结束,但如果我注销gestureRecognizer本身,他们都处于“已结束”状态:
-(void)didSwipe:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"did swipe called %@", gestureRecognizer);
}
控制台:
2011-01-05 12:57:43.478 App[20752:207] did swipe called <UISwipeGestureRecognizer: 0x5982fa0; state = Ended; view = <UITableViewCellContentView 0x5982c30>; target= <(action=didSwipe:, target=<RootViewController 0x5e3e080>)>; direction = right>
2011-01-05 12:57:43.480 App[20752:207] did swipe called <UISwipeGestureRecognizer: 0x5982fa0; state = Ended; view = <UITableViewCellContentView 0x5982c30>; target= <(action=didSwipe:, target=<RootViewController 0x5e3e080>)>; direction = right>
我是真的真的不知道为什么。我试着明确地检查了Ended状态,但这没有任何帮助,因为它们都以“End”结尾......任何想法?
谢谢!这阻止了它发射两次! :) – mootymoots 2011-01-05 17:55:03
谢谢,这有帮助,但我看到一些奇怪的 - 刷卡后,如果我想选择行,我需要按两次。第一次什么都不做,第二次调用didSelectRow ...有人看到了这个? – 2013-02-27 09:34:44
@OdedBenDov我相信这是由手势识别器引起的,当我添加了轻击手势识别器并忘记删除文本字段的末尾编辑方法(表格视图单元格的子视图)时,我有奇怪的表格视图单元格选择行为,可能是这可以作为解决你的问题的线索,更多细节[这里](http://stackoverflow.com/questions/9939509/strange-behavior-did-select-row-touch-not-responding-for-uitableviewcell) – 2013-08-28 10:26:19