dannybabiy / MSCMoreOptionTableViewCell

Drop-in solution to achieve the "More" button in an UITableView's "Swipe to Delete" menu (as seen in Mail.app under iOS 7)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MSCMoreOptionTableViewCell

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.

Screenshot

Integration

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

If you are using Storyboards in your project then take a look at the demo project which includes an working example using a Storyboard.

Add to your project

  1. Add MSCMoreOptionTableViewCell.xcodeproj as subproject.
  2. Add MSCMoreOptionTableViewCell's root folder to your project's header search paths.
  3. Add MSCMoreOptionTableViewCell to your target's dependencies (Target >> Build Phases >> Target Dependencies).
  4. Add MSCMoreOptionTableViewCell to your target's linked frameworks (Target >> Summary >> Linked Frameworks and Libraries).
  5. Import "MSCMoreOptionTableViewCell.h" either in Prefix.pch or seperatly in any file you use it.

Delegate

Required

- (void)tableView:(UITableView *)tableView moreOptionButtonPressedInRowAtIndexPath:(NSIndexPath *)indexPath;

Optional

- (NSString *)tableView:(UITableView *)tableView titleForMoreOptionButtonForRowAtIndexPath:(NSIndexPath *)indexPath;
- (UIColor *)tableView:(UITableView *)tableView titleColorForMoreOptionButtonForRowAtIndexPath:(NSIndexPath *)indexPath;
- (UIColor *)tableView:(UITableView *)tableView backgroundColorForMoreOptionButtonForRowAtIndexPath:(NSIndexPath *)indexPath;

Customizing

The 'More' button can be customized using the three optional delegate methods mentioned above.

Compatibility and Requirements

  • iOS 7 or newer
  • Xcode 5 or newer

As many other solutions that extend existing functionalities MSCMoreOptionTableViewCell 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.

Credits

MSCMoreOptionTableViewCell was created by Manfred Scheiner (@scheinem - scheinem.com). Of course there is also a full list of all contributors available.

License

MSCMoreOptionTableViewCell is available under the MIT license. See the LICENSE file for more info. For usage without attribution contact Manfred Scheiner.

About

Drop-in solution to achieve the "More" button in an UITableView's "Swipe to Delete" menu (as seen in Mail.app under iOS 7)

License:MIT License


Languages

Language:Objective-C 97.1%Language:Ruby 2.9%