在钛的多个窗口之间导航

时间:2012-02-29 07:48:35

标签: iphone window titanium

我们假设我有3个文件Window1.jsWindow2.jsWindow3.js

我可以从Window1导航到Window2,从Window2导航到Window3毫无问题。

当我想从window3回到window2时,我会这样做:window3.close(); 现在我在window2上想要回到window1,所以我做了:window2.close();。但是反而让我回到了window3而不是我想要的window1。有没有办法回到window1?有人可以解释我如何在这个钛窗口之间导航吗?谢谢

1 个答案:

答案 0 :(得分:6)

看看这个:the wiki提供了一个带有example code的精彩视频。也许你可以提供一些可以验证你的问题..
示例本身非常好,因为它适用于任意数量的窗口。它提供了一个堆栈:

this.windowStack = [];

将成为filset window.navbarHidden = true或以当前窗口引导,窗口将在导航组中打开。这提供了顶部的iphone导航栏(带后退键等)

this.windowStack.push(windowToOpen);
this.navGroup.open(windowToOpen);

该示例还提供了获取第一个窗口的可能性,即window1。为此,堆栈将被刷新

for(var i = 1, l = windows.length; i < l; i++) {
    (this.navGroup) ? this.navGroup.close(windows[i]) : windows[i].close();
}

<强> [更新]
如果您对导航栏不感兴趣,请设置

window1.navbarHidden = true

另外,您可以像这样编辑导航控制器:

exports.NavigationController.prototype.open = function(/*Ti.UI.Window*/windowToOpen) {
    //add the window to the stack of windows managed by the controller
    this.windowStack.push(windowToOpen);

    //grab a copy of the current nav controller for use in the callback
    var that = this;
    windowToOpen.addEventListener('close', function() {
        that.windowStack.pop();
    });

    //This is the first window
    if(this.windowStack.length === 1 && (Ti.Platform.osname === 'android')) {
        windowToOpen.exitOnClose = true;
    }

    // open
    windowToOpen.open();
};