2012-06-27 19 views
1

我有一個UITableView與其中的幾個UITableViewCells。我想長時間按住一個單元格開始移動並保持並拖動移動它。但我不知道如何。如何開始移動細胞與長按手勢?

我加了一個長按手勢上表來看,當用戶長按,設定的tableview的編輯爲YES:

UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] 
                initWithTarget:self 
                action:@selector(handleTableViewLongPress:)]; 
[_tableView addGestureRecognizer:longPressRecognizer]; 

- (void)handleTableViewLongPress:(UILongPressGestureRecognizer *)gesture 
{ 
    if (gesture.state != UIGestureRecognizerStateBegan) 
     return; 
    [_tableView setEditing:YES]; 
} 

而且tableview中可以用兩種方法移動電池:

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return YES; 
} 

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 
{ 
    //update datasource 
} 

但與這些代碼用戶必須使用兩個觸摸來移動一個單元格:一個是將tableview設置爲編輯狀態,另一個是移動單元格。我想要的是允許用戶使用一觸即可做到這一點。

有什麼建議嗎?謝謝!

+0

是的,我有。但長時間按下後,我需要再次觸摸移動單元格。我想要的是用戶只能使用一次觸摸。 – OpenThread

回答