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.
For swift programming
Swift 4
Johnny's answer is the right one to upvote. 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 :)
Make sure you declare the uitableviewdelegate and have the following methods:
To improve on Johnny's answer, this can now be done using the public API as follows :
Here is one simple solution. It is capable to display and hide custom UIView inside UITableViewCell. Displaying logic is contained inside class extended from UITableViewCell, BaseTableViewCell.
BaseTableViewCell.h
BaseTableViewCell.M
To get this functionality, simple extend your table view cell from BaseTableViewCell.
Next, Inside UIViewController, which implement UITableViewDelegate, create two gesture recognizers to handle left and right swipes.
Than add two swipe handlers
Now, inside cellForRowAtIndexPath, of UITableViewDelegate, you can create custom UIView and attach it to the dequeued cell.
Of course, this way of loading of custom UIView is just for this example. Manage it as you want.
This is not possible using the standard SDK. However there are various 3rd party solutions that more or less imitate the behavior in Mail.app. Some of them (e.g. MCSwipeTableViewCell, DAContextMenuTableViewController, RMSwipeTableViewCell) detect swipes using gesture recognizers, some of them (e.g. SWTableViewCell) put a second UISScrollView below the standard
UITableViewCellScrollView
(private subview ofUITableViewCell
) and some of them modify the behavior ofUITableViewCellScrollView
.I like the last approach most since the touch handling feels most natural. Specifically, MSCMoreOptionTableViewCell is good. Your choice may vary depending on your specific needs (whether you need a left-to-right pan, too, whether you need iOS 6 compatibility, etc.). Also be aware that most of these approaches come with a burden: they can easily break in a future iOS version if Apple makes changes in the
UITableViewCell
subview hierarchy.