Why is the sender of an UIMenuItem action always nil?

一世执手 提交于 2020-01-04 14:20:39

问题


I've added an UIMenuItem instance to UIMenuController. When I tap in a text field twice, then I get that text editing menu with Copy, Cut, Paste, Lookup in Wikipedia.

This is my action method:

- (void)lookupInWikipedia:(id)sender {
    NSLog(%@"lookupInWikipedia: sender=%@", sender);
}

I get the NSLog when I select the "Lookup in Wikipedia" menu item. But sender is always nil.

Not even the -canPerformAction:withSender: method receives anything other than nil for sender.

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
 NSLog(@"canPerformAction:withSender: = %@", sender);
 return YES;
}

Am I doing something wrong or is this a know framework bug?


回答1:


I also came across that once. Looks like a bug to me.



来源:https://stackoverflow.com/questions/4293869/why-is-the-sender-of-an-uimenuitem-action-always-nil

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