iOS 5中的“定义”编辑菜单项的select器

我正在build立自己的自定义编辑菜单(UIMenuController),并使用典型的

-(BOOL)canPerformAction:(SEL)action withSender(id)sender 

方法来有条件地启用/禁用系统默认值。 典型的编辑方法有很好的logging(copy :, cut :,等等),但是我找不到任何有关“Define”菜单选项调用什么方法来提取iOS 5中的新单词词典的问题。隐藏在明显的视野中,但我花了几个小时寻找它,所以我会很感激任何帮助。 具体来说,我需要:

 if (action == @selector(defineWord:)) ...... 

但是给我一个真正代替“defineWord”的地方:

PS – 我不介意知道该方法属于什么类,只是出于好奇(例如,复制:属于UIResponderStandardEditActions)

通过实施这个:

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

我能够看到select器是“_define:”。

定义select器(_define :)实际上是私有的,如果你使用它,你的应用将被拒绝。 我只需要在UITextView中显示Define菜单项就可以做到这一点:

 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(cut:) || action == @selector(copy:) || action == @selector(select:) || action == @selector(selectAll:) || action == @selector(paste:) || action == @selector(delete:)) { return NO; } else return [super canPerformAction:action withSender:sender]; } 

在iOS 7.1中,当重写canPerformAction:withSender:时,会看到以下操作canPerformAction:withSender: UIWebView的子类上的canPerformAction:withSender:方法:

 cut: copy: select: selectAll: paste: delete: _promptForReplace: _showTextStyleOptions: _define: _addShortcut: _accessibilitySpeak: _accessibilitySpeakLanguageSelection: _accessibilityPauseSpeaking: makeTextWritingDirectionRightToLeft: makeTextWritingDirectionLeftToRight: 

大概以下划线作为前缀的是“私人API”,它们的使用会让你的应用程序被App Store拒绝。 但是,我无法真正find任何一种方式的文件。

没有下划线的那些被定义为UIResponderStandardEditActions非正式协议的一部分。

简单的方法来做到这一点,而不使用私人API,返回YES只为想要的行动

 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender { if (action == @selector(MySelector:) { return [super canPerformAction:action withSender:sender] } else return NO; } 

请享用 ;)