Drop-in solution to achieve the "More" button in an UITableView's "swipe to delete"-menu (as seen in the Mail.app) by extending Apple's own "swipe to delete"-implemtation and not rewriting it, so UITableView's standard behaviour isn't changed.
If you are using a custom UITableViewCell subclass then change it to inherit from MSCMoreOptionTableViewCell instead of UITableViewCell. If your are using UITableViewCell itself just replace it with MSCMoreOptionTableViewCell (take a look at the following snippet for details). Then set the cell's delegate to your UITableViewController and you're ready to go!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"MSCMoreOptionTableViewCell";
MSCMoreOptionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[MSCMoreOptionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.delegate = self;
}
cell.textLabel.text = @"Cell";
return cell;
}
- Add MSCMoreOptionTableViewCell.xcodeproj as subproject.
- Add MSCMoreOptionTableViewCell's root folder to your project's header search paths.
- Add MSCMoreOptionTableViewCell to your target's dependencies (Target >> Build Phases >> Target Dependencies).
- Add MSCMoreOptionTableViewCell to your target's linked frameworks (Target >> Summary >> Linked Frameworks and Libraries).
- Import "MSCMoreOptionTableViewCell.h" either in Prefix.pch or seperatly in any file you use it.
- (void)tableView:(UITableView *)tableView moreOptionButtonPressedInRowAtIndexPath:(NSIndexPath *)indexPath;
The 'More' button can be customized using the following three properties of MSCMoreOptionTableViewCell:
- NSString *moreOptionButtonTitle
- UIColor *moreOptionButtonBackgroundColor
- UIColor *moreOptionButtonTitleColor
MSCMoreOptionTableViewCell is compatible to iOS 7 and above. As many other solutions that extends existing functionalities it depends on existing vendor code, therefore if Apple change it's "swipe to delete"-implementation significant in future iOS releases, it could happen that the "More" button doesn't appear until MSCMoreOptionTableViewCell gets adopted. But it's important for you as developer to know that MSCMoreOptionTableViewCell can't break your App or UITableView's standard functionality because of changes on the "swipe to delete"-implementation from Apple.
MSCMoreOptionTableViewCell was created by Manfred Scheiner (@scheinem - scheinem.com).
MSCMoreOptionTableViewCell is available under the MIT license. See the LICENSE file for more info. For usage without attribution contact Manfred Scheiner.