滑动到删除和“更多”按钮按钮(如iOS 7上的Mail应用程序) [英] Swipe to Delete and the "More" button (like in Mail app on iOS 7)

查看:106
本文介绍了滑动到删除和“更多”按钮按钮(如iOS 7上的Mail应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户在表格视图中滑动单元格时(如ios 7中的邮件应用程序),如何创建更多按钮

How to create a "more" button when user swipe a cell in table view (like mail app in ios 7)

我一直在寻找这些信息在这里和Cocoa Touch论坛,但我似乎无法找到答案,我希望比我更聪明的人能给我一个解决方案。

I have been looking for this information both here and in the Cocoa Touch forum, but I cannot seem to find the answer and I am hoping someone smarter than myself can give me a solution.

我希望当用户滑动表格视图单元格,以显示多个编辑按钮(默认为删除按钮)。
在适用于iOS 7的邮件应用中,您可以滑动删除,但会显示一个更多按钮。

I would like that when the user swipes a table view cell, to display more than one editing button (he default is the delete button). In the Mail app for iOS 7 you can swipe to delete, but there is a "MORE" button that shows up.

推荐答案

如何实现



看起来iOS 8打开了这个API。 Beta 2中提供了此类功能的提示。

How to Implement

It looks like iOS 8 opens up this API. Hints of such functionality are present in Beta 2.

要使某些工作正常,请在UITableView的委托上实现以下两种方法以获得所需的效果(请参阅示例的要点) )。

To get something working, implement the following two methods on your UITableView's delegate to get the desired effect (see gist for an example).

- tableView:editActionsForRowAtIndexPath:
- tableView:commitEditingStyle:forRowAtIndexPath:


文档说tableView:commitEditingStyle:forRowAtIndexPath是:

The documentation says tableView:commitEditingStyle:forRowAtIndexPath is:


没有使用UITableViewRowAction调用动作 - 动作的处理程序将被调用。

"Not called for edit actions using UITableViewRowAction - the action's handler will be invoked instead."

然而,没有它,滑动不起作用。即使方法存根是空白的,它现在仍然需要它。这显然是测试版2中的错误。

However, the swiping doesn't work without it. Even if the method stub is blank, it still needs it, for now. This is most obviously a bug in beta 2.


https://twitter.com/marksands/status/481642991745265664
https://gist.github.com/marksands/76558707f583dbb8f870

原始答案: https://stackoverflow.com/a/24540538/870028


使用此示例代码(在Swift中): http://dropbox.com/s/0fvxosft2mq2v5m /DeleteRowExampleSwift.zip

Sample code with this working (In Swift): http://dropbox.com/s/0fvxosft2mq2v5m/DeleteRowExampleSwift.zip

示例代码在MasterViewController.swift中包含这个易于理解的方法,只需使用此方法就可以获得显示的行为OP截图:

The sample code contains this easy-to-follow method in MasterViewController.swift, and with just this method you get the behavior shown in the OP screenshot:

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? {

    var moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More", handler:{action, indexpath in
        println("MORE•ACTION");
    });
    moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);

    var deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler:{action, indexpath in
        println("DELETE•ACTION");
    });

    return [deleteRowAction, moreRowAction];
}

这篇关于滑动到删除和“更多”按钮按钮(如iOS 7上的Mail应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆