如何修复Appcelerator's”;“导航控制器”;使用TabGroup作为基本窗口

How can I fix Appcelerator's "Navigation Controller" to work with a TabGroup as the base window?

本文关键字:TabGroup 使用 窗口 导航控制器 导航 Appcelerator 何修复 控制器      更新时间:2023-09-26

我一直在看Appcelerator Vimeo频道上的一些Titanium Appcelerator教程,更具体地说,这是一个:跨平台导航控制器。我发现将它与一个基本的应用程序集成起来相当容易,但我在使用tabGroups时遇到了一些困难。

问题是,当创建选项卡并将放置到tabGroup中时,tabGroup窗口本身似乎没有被放置到导航控制器的堆栈上。这是那个控制器的代码。基本上,这意味着如果我从tabGroup中点击到一个新窗口,我不会得到原始窗口的"返回按钮"。然而,如果我进一步点击,子序列窗口确实有这个"后退按钮"功能。

知道是什么原因造成的吗?代码的基本概述如下,NavigationController代码如上所述链接。提前感谢您的帮助。

app.js:

(function() {
    var NavigationController = require('NavigationController');
    var windowObject = require('iPhoneWindow');
    new windowObject(new NavigationController()).open();
});

iPhone Window.js:

exports.iPhoneWindow = function(navController) {
    var NewsView = require('newsView');
    var instance = Ti.UI.createTabGroup({
        backgroundColor: '#FFF'
    });
    var newsTab = Ti.UI.createTab({
        window: new NewsView(navController),
        title: 'News'
    });
    instance.addTab(newsTab);
    return instance;
};

newsView.js:

exports.newsView = function(navController) {
    var instance = Ti.UI.createWindow({
        title: 'News',
        backgroundColor: '#000';
    });
    var button = Ti.UI.createButton({
        title: 'newsButton',
        height: 60,
        width: 180,
        top: 150
    });
    button.addEventListener('click', function() {
        navController.open(new exports.newsView(navController));
    });
    instance.add(button);
    return instance;
};

您不需要将跨平台导航控制器与TabGroup一起使用-每个选项卡都有自己的导航堆栈,在iOS设备上,它会自动为您提供一个包含所有装饰的导航控制器。要打开堆栈上的窗口,您需要获得活动选项卡,并打开该选项卡上的窗口-因此将您的选项卡组传递到newsView:

exports.newsView = function(tabGroup) {
    var instance = Ti.UI.createWindow({
        title: 'News',
        backgroundColor: '#000';
    });
    var button = Ti.UI.createButton({
        title: 'newsButton',
        height: 60,
        width: 180,
        top: 150
    });
    button.addEventListener('click', function() {
        tabGroup.activeTab.open(new exports.newsView(tabGroup));
    });
    instance.add(button);
    return instance;
};