我想在我的 ObjC 应用程序中在运行时禁用菜单栏中的剪切和/或粘贴。我知道在 iOS 中使用 -(BOOL)canPerformAction:(SEL)aSelector withSender:(id)sender 是可能的
MacOS有类似的东西吗?
谢谢
我想在我的 ObjC 应用程序中在运行时禁用菜单栏中的剪切和/或粘贴。我知道在 iOS 中使用 -(BOOL)canPerformAction:(SEL)aSelector withSender:(id)sender 是可能的
MacOS有类似的东西吗?
谢谢
有NSUserInterfaceValidations Protocol,一个用于验证项目的通用协议。您只需实现该validateUserInterfaceItem:
方法并返回 NO 即可禁用该操作。
- (BOOL)validateUserInterfaceItem:(id < NSValidatedUserInterfaceItem >)anItem {
if([anItem action] == @selector(cut:) ||
[anItem action] == @selector(copy:) ||
[anItem action] == @selector(paste:)) return NO;
return [self respondsToSelector:[anItem action]];
}
还有一个NSMenuValidation Protocol,它执行相同的功能,但仅用于验证菜单项,而不是所有界面项。如果您不实施它,系统将改为退回到标准验证。