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