2012-01-02 112 views
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

也許您應該禁用單元格選擇 - 通常會觸發單元格重新加載。