0

在我的UITableViewCell中,我有UISwipeGestureRecognizer在单元格中滑动图像,并且卡住了。例如,GestureRecognizer调用方法,增加图像数量并重新加载行。如何定义被触摸的行并将其传递给方法?UITableViewCell中的UIGestureRecognizer

+0

您能否包含一些代码?你处理滑动的方法会很好。 – jrturton 2012-01-02 12:00:40

回答

1

我发现,我们可以通过触摸坐标定义swiped cell。它看起来像这样:

if (recognizer.state == UISwipeGestureRecognizerStateEnded) { 
    CGPoint gestureLocation = [recognizer locationInView:self.tableView]; 
    NSIndexPath *swipedIndexPath = [self.tableView indexPathForRowAtPoint:gestureLocation]; 
//found IndexPath for swiped cell. Now we can do anything what we need. 
//In my case it's cell reloading with new image in UIImageView. 
NSArray *rowsToReload = [[NSArray alloc] initWithObjects:swipedIndexPath, nil]; 
[self.tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone]; 
+0

你的if语句缺少结束括号,究竟应该去哪里? – 2012-09-19 15:16:34

0

也许您应该禁用单元格选择 - 通常会触发单元格重新加载。