繁体   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