簡體   English   中英

如何開始長按手勢移動單元格?

[英]how to begin moving cell with long press gesture?

我有一個帶有幾個UITableViewCells的UITableView。 我想長按一個單元格以開始移動它,並按住它並拖動以移動它。 但是我不知道如何。

我在表格視圖上添加了長按手勢,當用戶長按時,將表格視圖的編輯設置為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
}

但是使用這些代碼,用戶必須使用兩次觸摸才能移動單元格:一種是將表格視圖設置為編輯狀態,另一種是移動單元格。 我想要的是允許用戶使用一鍵式操作。

有什么建議么? 謝謝!

我找到了這個UITableView子類: 移動表視圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM