1

i am trying to show popup with 2 options in it (Copy and Delete) but at the moment code is only showing Copy in it please view my code below.

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
    return (action == @selector(copy:)) || (action == @selector(delete:));
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
    if (action == @selector(copy:))
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
        [pasteBoard setString:cell.textLabel.text];
    }
    if (action == @selector(delete:))
    {
        NSLog(@"delete pressed!");
    }

}
Vix Hunk
  • 303
  • 4
  • 17
  • Hey, check this SO link. [SO link for Custom Menu Item](http://stackoverflow.com/questions/12290828/how-to-show-a-custom-uimenuitem-for-a-uitableviewcell) It says, even though we you expect tableView canPerformAction: to support custom selectors while the documentation says it supports only two of UIResponderStandardEditActions (copy and/or paste); – Sanu S May 10 '16 at 08:55
  • but then how is that working on Whatsapp and lots of other apps? – Vix Hunk May 10 '16 at 09:05
  • They might also be using the same approach. But, sure that default delete will not show up as menu item as in your current code. I believe, you need to implement some more customization mentioned in that link. – Sanu S May 10 '16 at 09:16

2 Answers2

0

I have used this library to implement swippable buttons which supports a variety of transitions and expandable buttons.

https://github.com/MortimerGoro/MGSwipeTableCell

This library is compatible with all the different ways to create a UITableViewCell and its working fine on latest versions of iOS as well.

enter image description here

P.S. I suggest you to provide UI like this.

Hemang
  • 26,840
  • 19
  • 119
  • 186
-1

Try to replace

return (action == @selector(copy:)) || (action == @selector(delete:));

with

return (action == @selector(copy:)) && (action == @selector(delete:));

Hope this will help :)

Ketan Parmar
  • 27,092
  • 9
  • 50
  • 75