簡體   English   中英

iOS在UITableView上從左滑動,同時保持滑動以刪除

[英]iOS swipe from left on UITableView while remaining Swipe to delete

我使用簡單的蘋果代碼實現了從右向左滑動以在tableview中刪除,但是我還想從左向右添加自己的滑動以添加另一個按鈕。 基本上,我希望具有與刪除滑動相同的功能,但是我將擁有一個自定義按鈕,並且自定義滑動將從相反的一側開始,而刪除滑動將保持功能正常。

為了使其直觀,我嘗試使用UIPanGestureRecognizer ,以便用戶在滑動時可以看到單元格在移動(就像要刪除的滑動一樣)。 但是,我不知道如何移動實際的單元格,以及如何在其下方添加按鈕。

我想我瀏覽了整個互聯網,但找不到。 你有什么建議嗎?

這是一篇很好的文章,可以幫助您從概念上開始http://www.teehanlax.com/blog/reproduction-the-ios-7-mail-apps-interface/

此外,還有幾種開源解決方案:

(您應該判斷代碼質量)

這只是(希望)iOS8即將發布的功能的預告片https://gist.github.com/steipete/10541433

我創建了一個新庫來實現可滑動按鈕,該按鈕支持各種轉換和可擴展按鈕,例如iOS 8郵件應用程序。

https://github.com/MortimerGoro/MGSwipeTableCell

該庫與創建UITableViewCell的所有不同方式兼容,並且已在iOS 5,iOS 6,iOS 7和iOS 8上進行了測試。

在此處輸入圖片說明

Gami的答案是正確的答案。 我只是在Objective-C中添加以下內容,以使初學者(以及我們中那些拒絕學習Swift語法的人)更加清楚:

確保聲明uitableviewdelegate並具有以下方法:

-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
 UITableViewRowAction *button = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 1" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
    {
        NSLog(@"Action to perform with Button 1");
    }];
    button.backgroundColor = [UIColor greenColor]; //arbitrary color
    UITableViewRowAction *button2 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"Button 2" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath)
                                    {
                                        NSLog(@"Action to perform with Button2!");
                                    }];
    button2.backgroundColor = [UIColor blueColor]; //arbitrary color

    return @[button, button2]; //array with all the buttons you want. 1,2,3, etc...
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
// you need to implement this method too or nothing will work:

}
 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return YES; //tableview must be editable or nothing will work...
    }

暫無
暫無

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

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