0

I am working on adding custom shared menu. I followed this stackoverflow post to implement this also seen some other posts.

It is working as it should be. But I am getting problem to get called canPerformAction when coming on this UITableView Controller by UITabBar item action which navigate me back to this view.

I tried to sovle this problem by using one of the answer on stackoverflow. But still canPerformAction not getting called in this case

Any help in this case is appritiated. Thanks

EDIT: My code looks like:

On viewDidLoad, i am doing following

UIMenuItem *sendByEmailMenuItem = [[UIMenuItem alloc] initWithTitle:@"Send e-mail" action:@selector(sendEmail:)];
[[UIMenuController sharedMenuController] setMenuItems: @[sendEmailMenuItem]];
[[UIMenuController sharedMenuController] update];

These are delegate methods i have used

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
    return NO;
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {

}

- (BOOL) canPerformAction:(SEL)action withSender:(id)sender {
    return (action == @selector(sendEmail:));
}

- (BOOL)canBecomeFirstResponder {
    return YES;
}

- (void) sendEmail: (id) sender {
       //do stuff
}
Community
  • 1
  • 1
User16119012
  • 957
  • 11
  • 25
  • Doubt this will fix the issue, but do check your third delegate method; should be a (void)tableView:performAction:forRowAtIndexPath instead of BOOL – azsromej Feb 19 '14 at 15:59
  • @azsromej: Thanks, I followed the post in question. I will check it from docs and change it – User16119012 Feb 20 '14 at 06:53

1 Answers1

0

Fixed this issue. Posting it if some one needs it.

I have added a call to become fist respoder on shouldShowMenuForRowAtIndexPath action

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath {
    [self becomeFirstResponder];
    return YES;
}

This fixed my issue. Thanks

User16119012
  • 957
  • 11
  • 25