1

我打开窗口如下:app.js:

    var NavigationController = require('NavigationController').NavigationController, 
TestWindow = require('main_windows/tmain').TestWindow;

//create NavigationController which will drive our simple application
var controller = new NavigationController();

//open initial window
controller.open(new TestWindow(controller));


function openWindow(name, naController, event) {
    var TestWindow2 = require('main_windows/t' + name).TestWindow;

    var win = Titanium.UI.currentWindow;

    var swin = Titanium.UI.createWindow();

    if(event.bid)
        swin.bid    = event.bid;

    if(event.uniq)
        swin.uniq = event.uniq;

    if (event.zipcode)
        swin.zipcode = event.zipcode;

    if (event.user_id)
        swin.user_id = event.user_id;

    if (event.service_id)
        swin.service_id = event.service_id;

    if (event.service_name)
        swin.service_name = event.service_name;

    if (event.user_uniqid)
        swin.user_uniqid = event.user_uniqid;

    if (event.user_name)
        swin.user_name = event.user_name;

    if (event.user_email)
        swin.user_email = event.user_email;

    if (event.provider_id)
        swin.provider_id = event.provider_id;

    if (event.provider_name)
        swin.provider_name = event.provider_name;

    if (event.total)
        swin.total = event.total;

    if(event.response)
        swin.response   = event.response;

    swin.backgroundColor = '#f7f7f7';
    swin.barImage = 'images/example.gif';


    naController.open(new TestWindow2(naController, swin));


}

这是 NavigationController.js

    exports.NavigationController = function() {
    this.windowStack = [];
};

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);

    //alert('open' + this.windowStack.length);

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

        // alert('open' + that.windowStack.length);

        if(that.windowStack.length > 1)
        {

            //alert('pop' + that.windowStack.length);
            that.windowStack.pop();
        }
    });

    //hack - setting this property ensures the window is "heavyweight" (associated with an Android activity)
    windowToOpen.navBarHidden = windowToOpen.navBarHidden || false;

    //This is the first window
    if(this.windowStack.length === 1) {


        if(Ti.Platform.osname === 'android') {
            windowToOpen.exitOnClose = true;
            windowToOpen.open();
        } else {

            //alert('nav' + this.windowStack.length);

            this.navGroup = Ti.UI.iPhone.createNavigationGroup({
                window : windowToOpen
            });
            var containerWindow = Ti.UI.createWindow();
            containerWindow.add(this.navGroup);
            containerWindow.open();
        }
    }
    //All subsequent windows
    else {


        if(Ti.Platform.osname === 'android') {
            windowToOpen.open();
        } else {

            //alert('nav2' + this.windowStack.length);

            this.navGroup.open(windowToOpen);
        }
    }
};

//go back to the initial window of the NavigationController
exports.NavigationController.prototype.home = function() {
    //store a copy of all the current windows on the stack

    //alert('reset' + this.windowStack.length);

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


    //alert('n' + this.windowStack.length);
};

这是 tmain.js

    exports.TestWindow = function(navController) {

    var win = Ti.UI.createWindow({
        backButtonTitleImage : 'images/backb.gif',
        fullscreen : false,
        navBarHidden : true,
    });

    var t1 = null;

    win.backgroundImage = 'images/back.jpg';

    var view = Titanium.UI.createView({
        width : '100%',
        height : '100%',
        top : 270,
        layout : 'vertical'
    });

    var b3 = Titanium.UI.createImageView({
        url : 'images/login.gif',
        height : 80
    });
    view.add(b3);

    var b4 = Titanium.UI.createImageView({
        url : 'images/signup.gif',
        top : 0,
        height : 80
    });
    view.add(b4);

    win.add(view);

    var list1 = function(e) {
        openWindow('login', navController, e);
    };
    b3.addEventListener('click', list1);

    var list2 = function(e) {
        openWindow('register', navController, e);
    };
    b4.addEventListener('click', list2);

    win.addEventListener('close', function (e) {
        alert(3);
        b3.removeEventListener('click', list1);
        b4.removeEventListener('click', list2);
    });

    return win;
};

所以我使用 openWindow 函数在应用程序中打开窗口。我有一个注销按钮,当人们单击它时,会调用函数 navController.home() (请参阅导航控制器),但问题是单击注销链接会导致窗口状态损坏 - 这意味着应用程序崩溃并且当您尝试打开它,窗口混合在一起(就像窗口 3 中的按钮显示在窗口 2 中一样)。我究竟做错了什么?

4

0 回答 0