【问题标题】:iOS swipe from left on UITableView while remaining Swipe to deleteiOS 在 UITableView 上从左侧滑动,同时保持滑动删除
【发布时间】:2015-10-28 20:15:58
【问题描述】:

我使用简单的苹果代码实现了从右到左的滑动以在我的 tableview 中删除,但我还想为另一个按钮添加我自己的从左到右的滑动。基本上,我想要与滑动删除相同的功能,但我将有一个自定义按钮,并且自定义滑动将来自另一侧,而滑动删除将保持功能。

为了直观起见,我尝试使用UIPanGestureRecognizer,以便用户在滑动时可以看到单元格移动(就像滑动删除一样)。但是,我不知道如何移动实际的单元格,另外,如何在其下方添加一个按钮。

我想我浏览了整个互联网,但找不到。你有什么建议吗?

【问题讨论】:

    标签: ios objective-c uitableview uipangesturerecognizer


    【解决方案1】:

    这是一篇很好的文章,可让您在概念层面上开始 http://www.teehanlax.com/blog/reproducing-the-ios-7-mail-apps-interface/

    此外还有几种开源解决方案:

    (你应该判断代码质量)

    这只是(希望)iOS8 即将推出的功能的预告https://gist.github.com/steipete/10541433

    【讨论】:

    • 这看起来很棒!感谢您的时间和所有这些有用的链接。我可能会坚持使用你给我的开源解决方案之一。
    【解决方案2】:

    我创建了一个新库来实现可滑动按钮,它支持各种转换和可扩展按钮,例如 iOS 8 邮件应用程序。

    https://github.com/MortimerGoro/MGSwipeTableCell

    该库兼容创建 UITableViewCell 的所有不同方法,并在 iOS 5、iOS 6、iOS 7 和 iOS 8 上进行了测试。

    【讨论】:

      【解决方案3】:

      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...
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-18
        • 1970-01-01
        • 1970-01-01
        • 2018-03-19
        相关资源
        最近更新 更多