应用程序退出事件 [英] Application exit event

查看:333
本文介绍了应用程序退出事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序在可可。我的应用程序显示一个弹出窗体最初。我需要知道哪个事件被触发,当我们试图退出应用程序通过右键单击并选择退出在图标在坞站,因为我不能退出应用程序,因为弹出窗口。查看解决方案

I am developing an application in cocoa .My application shows a pop up sheet initially .Now i need to know which event is fired when we try to exit the application by right clicking and selecting "exit" on the icon in dock,because i cant exit the appication because of the popup sheet ..looking for a solution

推荐答案

$ c> quit 在Dock菜单中选择Quit项时的Apple事件。如果要拦截此事件,您需要为此事件安装一个自定义Apple事件处理程序。请注意,在工作表被关闭之前,工作表可以阻止应用程序终止,因此,如果您更改此行为,您的应用程序将与其他应用程序的工作方式不同。

Your app is sent a quit Apple Event when the Quit item is selected in the Dock menu. If you want to intercept this you will need to install a custom Apple Event Handler for this event. Note that it's normal for sheets to prevent application termination until the sheet is dismissed, so if you change this behavior your app will work differently to other applications.

这里是一个简单的如何覆盖退出的默认处理程序示例

Here is a simple example of how to override the default handler for quit Apple Events in your application delegate:

- (void)applicationDidFinishLaunching:(NSNotification*)notification
{
    //install the custom quit event handler
    NSAppleEventManager* appleEventManager = [NSAppleEventManager sharedAppleEventManager];
    [appleEventManager setEventHandler:self andSelector:@selector(handleQuitEvent:withReplyEvent:) forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
}

//handler for the quit apple event
- (void)handleQuitEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
{
    [self terminate:self];
}

这篇关于应用程序退出事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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