
- (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>
我真的不知道为什么。我试图明显地检查结束状态,但这是没有帮助,因为他们都以“结束”反正…任何想法?
解决方法 而不是直接将手势识别器添加到单元格,可以将其添加到vIEwDIDLoad中的tablevIEw。在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问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)