1

我正在寻找一种方法来告诉应用程序确认您是否真的要在丢失项目更改之前关闭应用程序。

通过当前的 API,我无法做到。查看 Air/Flex 是如何做到这一点的,它看起来像是关闭时窗口的事件监听器:

<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   maxHeight="1080"
                   maxWidth="1920"
                   minWidth="1280"
                   minHeight="720" 
                   showStatusBar="false" 
                   creationComplete="startUp()"
                   closing="closeWindow(event)"
                   >

当我通过 Window 界面或通过应用程序菜单关闭窗口时,它执行了我所期望的,窗口关闭前的提示

Do you want to exit the application?/Do you want to exit without saving changes?
yes no.

TideSDK/TideKIT 有这种行为吗?如果是这样,请附上一个例子。了解如何正确地做这件事对我来说非常重要。

谢谢。

4

1 回答 1

2

这个例子帮助我在我的 TideSDK 应用程序中做类似的事情: https ://gist.github.com/MisterPoppet/4639473

从那里的示例中提取,您可能可以执行以下操作来完成您的要求:

var appWindow = Ti.UI.getCurrentWindow();

appWindow.addEventListener(Ti.CLOSE, function(event) {
    var r = confirm("Do you want to exit the application?");
    if (r == true) {
        //close
    } else {
        //cancel close
        event.preventDefault();
        return false;
    }
});
于 2014-03-10T15:47:53.113 回答