大佬教程收集整理的这篇文章主要介绍了ios – 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方法在成功滑动时总是调用两次。我最初认为这是因为手势开始和结束,但如果我退出手势识别器本身,他们都处于“已结束”状态:
-(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>
我真的不知道为什么。我试图明显地检查结束状态,但这是没有帮助,因为他们都以“结束”反正…任何想法?
在didSwipe方法中,您可以确定受影响的IndexPath和单元格如下:
-(void)didSwipe:(UIGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state == UIGestureRecognizerStateEnded) { CGPoint swipeLOCATIOn = [gestureRecognizer LOCATIOnInView:self.tableView]; NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:swipeLOCATIOn]; UITableViewCell* swipedCell = [self.tableView cellForRowATindexPath:swipedIndexPath]; // ... } }
以上是大佬教程为你收集整理的ios – UIGestureRecognizer和UITableViewCell问题全部内容,希望文章能够帮你解决ios – UIGestureRecognizer和UITableViewCell问题所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。