[英]iOS swipe from left on UITableView while remaining Swipe to delete
I implemented the swipe from right to left to delete in my tableview using simple apple code, but I also want to add my own swipe from left to right for another button. 我使用简单的苹果代码实现了从右向左滑动以在tableview中删除,但是我还想从左向右添加自己的滑动以添加另一个按钮。 Basically, I want the same functionality as with swipe to delete, but I will have a custom button, and the custom swipe will be from opposite side while swipe to delete will remain functional. 基本上,我希望具有与删除滑动相同的功能,但是我将拥有一个自定义按钮,并且自定义滑动将从相反的一侧开始,而删除滑动将保持功能正常。
To make it intuitive, I tried using UIPanGestureRecognizer
, so that a user can see the cell moving while he is swiping (just like the swipe to delete). 为了使其直观,我尝试使用UIPanGestureRecognizer
,以便用户在滑动时可以看到单元格在移动(就像要删除的滑动一样)。 However, I don't know how to move the actual cell, and additionally, how to add a button below it. 但是,我不知道如何移动实际的单元格,以及如何在其下方添加按钮。
I think I browsed the whole internet and I couldn't find it. 我想我浏览了整个互联网,但找不到。 Do you have any suggestions? 你有什么建议吗?
Here is a good article to get you started http://www.teehanlax.com/blog/reproducing-the-ios-7-mail-apps-interface/ on the conceptual level. 这是一篇很好的文章,可以帮助您从概念上开始http://www.teehanlax.com/blog/reproduction-the-ios-7-mail-apps-interface/ 。
Besides there are several open source solutions: 此外,还有几种开源解决方案:
(You should judge the code quality) (您应该判断代码质量)
And this is just a teaser for (hopefully) upcoming functionality of iOS8 https://gist.github.com/steipete/10541433 这只是(希望)iOS8即将发布的功能的预告片https://gist.github.com/steipete/10541433
I have created a new library to implement swippable buttons which supports a variety of transitions and expandable buttons like iOS 8 mail app. 我创建了一个新库来实现可滑动按钮,该按钮支持各种转换和可扩展按钮,例如iOS 8邮件应用程序。
https://github.com/MortimerGoro/MGSwipeTableCell https://github.com/MortimerGoro/MGSwipeTableCell
This library is compatible with all the different ways to create a UITableViewCell and its tested on iOS 5, iOS 6, iOS 7 and iOS 8. 该库与创建UITableViewCell的所有不同方式兼容,并且已在iOS 5,iOS 6,iOS 7和iOS 8上进行了测试。
Gami's answer is the right one to upvote. Gami的答案是正确的答案。 I'm just adding this below in objective-c to make it clearer to beginners (and those of us who refuse to learn Swift syntax :) 我只是在Objective-C中添加以下内容,以使初学者(以及我们中那些拒绝学习Swift语法的人)更加清楚:
Make sure you declare the uitableviewdelegate and have the following methods: 确保声明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.