可可如何阻止“退出"停靠菜单上的菜单项 [英] cocoa how to block the "Quit" menu item on dock menu
问题描述
我的停靠栏菜单总是自动添加退出"和其他 2 个菜单项,我该如何阻止/修改它们?
my dock menu always be added "Quit" and other 2 menu items automatically, how may I block / modify them?
更新:
真的没有办法删除/阻止/重定向退出"菜单项.最终像打击一样使用了彼得的推荐希望对其他人有帮助
really NO way to delete/block/redirect the "Quit" menu item. used Peter's recommendation at last like blow hope helpful to others
-(NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
{
if (needPassword)
{
[self checkPassword:self];
return NSTerminateCancel;
}
else
{
return NSTerminateNow;
}
}
-(void)checkPassword:(id)sender
{
if(passwordCorrect)
{
!needPassword;
[[NSApplication sharedApplication] terminate:self];
}
}
推荐答案
试图拦截用户可能告诉您的应用程序退出的所有可能方式注定会失败.(你还记得退出苹果事件吗?)
Trying to intercept all possible ways the user might tell your application to quit is bound to fail. (Did you remember the Quit Apple Event?)
实施 应用程序委托中的 applicationShouldTerminate:
方法.竖起密码面板,返回NSTerminateLater
.然后,当用户输入正确的密码或取消时,发送应用程序 a replyToApplicationShouldTerminate:
消息.
It'll be both easier and more effective to just implement the applicationShouldTerminate:
method in your application's delegate. Put up the password panel and return NSTerminateLater
. Then, when the user either enters the correct password or cancels, send the application a replyToApplicationShouldTerminate:
message.
无论您已经删除了哪些退出命令(菜单项等),请将它们放回去.让用户以正常方式调用正常的 Quit 命令;这将触发上述应该终止的程序,以确定是否真的会发生戒烟.
Whichever Quit commands (menu items, etc.) you've already ripped out, put them back. Let the user invoke the normal Quit command in the normal way; that will trigger the aforementioned should-terminate procedure to determine whether the quit will actually happen.
这篇关于可可如何阻止“退出"停靠菜单上的菜单项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!