ios 6 - canperformaction not getting called on UITableViewController

流过昼夜 提交于 2020-01-17 05:21:09

问题


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
}

回答1:


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



来源:https://stackoverflow.com/questions/21852971/ios-6-canperformaction-not-getting-called-on-uitableviewcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!