簡體   English   中英

向左滑動即可刪除和編輯,刪除

[英]Left swipe for delete and edit,delete

我找不到解決此問題的方法。 是否可以使用向左滑動以及使用編輯和刪除來具有刪除選項。

我在導航欄的左側有一個編輯按鈕。

self.navigationItem.leftBarButtonItem = self.editButtonItem;

和commitEditingStyle方法如下

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
//delete code here
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }   

}

使用此功能后,根本不會檢測到左滑動。 刪除的唯一方法似乎是進入編輯模式並從那里刪除。 幫助將不勝感激。

我是新手,所以請和我一起輕松:)

您的意思是在單元格上滑動需要刪除選項。

如果是這樣,您可以嘗試以下代碼:

- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {

    return UITableViewCellEditingStyleDelete;

}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    //perform delete operation

}

確保您在下面實現了所有代表

tableView:commitEditingStyle:forRowAtIndexPath:
tableView:canEditRowAtIndexPath:
tableView:editingStyleForRowAtIndexPath

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
//delete code here
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
    // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
    }  

一旦在委托中編寫了上述方法,您就可以使用滑動手勢...。在此方法中,您將處理要執行的后續操作。

謝謝.....

暫無
暫無

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

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