可可如何阻止“退出"?停靠菜单上的菜单项 [英] cocoa how to block the "Quit" menu item on dock menu

查看:72
本文介绍了可可如何阻止“退出"?停靠菜单上的菜单项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的停靠菜单始终会自动添加退出"和其他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?)

仅实现

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆