0

私のアプリでは、人々はウィンドウ 1 からウィンドウ 2、ウィンドウ 3 などに移動するため、ナビゲーションはウィンドウ 1 -> ウィンドウ 2 -> ウィンドウ 3 のようになります。

あるウィンドウから次のウィンドウに移動するには、ナビゲーション グループを使用します。

var main = Titanium.UI.createWindow({
    height:Ti.Platform.displayCaps.platformHeight,  
    width:Ti.Platform.displayCaps.platformWidth,  
    fullscreen:true, 
    navBarHidden : true,
});

var first = Ti.UI.createWindow({
    height:Ti.Platform.displayCaps.platformHeight,  
    width:Ti.Platform.displayCaps.platformWidth,  
    url:'main_windows/main.js',
    backButtonTitleImage : '../images/backb.gif',
    fullscreen:true, 
    navBarHidden : true,
});

var navGroup = Ti.UI.iPhone.createNavigationGroup({
    window:first
});

Ti.App.addEventListener('login', function(event)
{
    var lwin = Ti.UI.createWindow({
        height:Ti.Platform.displayCaps.platformHeight,  
        width:Ti.Platform.displayCaps.platformWidth,  
        url:'main_windows/login.js',
        barImage: 'images/lback.gif', 
        fullscreen:true, 
        backgroundColor: '#f7f7f7',
        navBarHidden : false,
        _parent : Titanium.UI.currentWindow,
        navGroup : navGroup,
        rootWindow : first 
    });

    navGroup.open(lwin);
});

first.navGroup = navGroup;

main.add(navGroup);

main.open();

~~~

次に、各ウィンドウで、次のようにして次のウィンドウを開きます。

~~~

button1.addEventListener('click', function() {
    Ti.App.fireEvent('services', {
        zipcode : win.zipcode,
        user_id : win.user_id,
        user_uniqid : win.user_uniqid,
        user_name : win.user_name,
        user_email : win.user_email
    });
});

Ti.App.addEventListener('services', function(event) {
    var cwin = Titanium.UI.currentWindow;
    var swin = Titanium.UI.createWindow();

    swin.url = 'service.js';

    swin.zipcode = event.zipcode;
    swin.user_id = event.user_id;
    swin.user_uniqid = event.user_uniqid;
    swin.user_name = event.user_name;
    swin.user_email = event.user_email;

    swin.backgroundColor = '#f7f7f7';

    swin._parent = cwin;
    swin.navGroup = cwin.navGroup;
    swin.rootWindow = cwin.rootWindow;
    cwin.navGroup.open(swin);
});

~~~

これは、人々がウィンドウ 1 -> ウィンドウ 2 -> ウィンドウ 3 に移動するときはうまく機能しますが、戻るときは機能しません。

Window 1 -> Window 2 -> Window 3 -> Window 1 -> Window 2 のように

それが起こると、次のエラーが発生します。

予期しない状態でのナビゲーション遷移の終了。ナビゲーション バーのサブビュー ツリーが破損する場合があります。

これを防ぐにはどうすればよいですか?

4

1 に答える 1

0

urlの属性を使用して複数の JavaScript コンテキストを開いていますcreateWindow。これにより、特に 2 つ以上の重いウィンドウで、システム メモリがかなり高速に消費されます。各ウィンドウを CommonJS モジュールに入れます。

これはあなたの問題を解決しないかもしれませんが、それは悪い習慣であり、その副作用が原因である可能性があります.

//Dont do this!!

var first = Ti.UI.createWindow({
    ...
    url:'main_windows/main.js', // Bad, opens a new context
    ...
});

代わりに、次のように独自の CommonJS モジュール ファイルに配置します。

// main_windows/main.js

function MainWindow() {
    var self = Ti.UI.createWindow();
    // Do all the initialization you were doing to this window in 'main_windows/main.js'
    return self;
}
module.exports = MainWindow;

次のようにインスタンス化します。

var MainWindow = require('main_windows/main.js');
var first = new MainWindow();

これで問題が解決するか、少なくともコードとリソースをより管理しやすい状態に分解できます。

于 2012-09-26T23:16:19.520 に答える