How to create a "more" button when user swipe a cell in table view (like mail app in ios 7)
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.
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.
In iOS 13, you can tap "Edit," tap-and-hold briefly on an email's bubble, then slide your finger up or down the screen on the bubbles until all of the emails you want to delete are highlighted. Let go, then hit "Trash," and confirm with "Trash Selected Messages."
It looks like iOS 8 opens up this API. Hints of such functionality are present in Beta 2.
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:
The documentation says tableView:commitEditingStyle:forRowAtIndexPath is:
"Not called for edit actions using UITableViewRowAction - the action's handler will be invoked instead."
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
Original Answer: https://stackoverflow.com/a/24540538/870028
Sample code with this working (In Swift): http://dropbox.com/s/0fvxosft2mq2v5m/DeleteRowExampleSwift.zip
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]; }
I have created a new library to implement swippable buttons which supports a variety of transitions and expandable buttons like iOS 8 mail app.
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.
Here a sample of some transitions:
Border transition:
Clip transition
3D Transition:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With