如何修复 Appcelerator 的“导航控制器”问题使用 TabGroup 作为基本窗口?

发布于 2024-12-26 04:02:12 字数 1688 浏览 0 评论 0原文

我一直在 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();
});

iPhoneWindow.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;
};

I've been looking over some of the Titanium Appcelerator tutorials on the appcelerator Vimeo channel, more specifically this one: A Cross-Platform Navigation Controller. I have found it fairly easy to integrate this with a basic app, but I am having some trouble getting it to work with tabGroups.

The issue is that when creating the tabs and placing the into the tabGroup, it seems that the tabGroup window itself does not get placed onto the stack in the navigation controller. Here is the code for that controller. Basically, this means that if I click through to a new window from the tabGroup, I don't get a 'back button' to the original window. If I click further in, however, subsequence windows do have this 'back button' functionality'.

Any idea what could be causing this? The basic overview of the code is below, and the NavigationController code is as linked above. Thanks ahead of time for any help.

app.js:

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

iPhoneWindow.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;
};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遥远的绿洲 2025-01-02 04:02:12

您不需要将跨平台导航控制器与 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;
};

You don't need to use that cross platform navigation controller with a TabGroup - each tab comes with its own navigation stack, that on iOS devices will automatically give you a navigation controller with all the trimmings. To open windows on a stack, you'll need to instead get the active tab, and open the window on that - so pass in your tabgroup to the newsView instead:

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;
};
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文