问题
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