【问题标题】:Detect back button click in NavigationWindow in a SplitWindow (Master/Detail) on Titanium Appcelerator在 Titanium Appcelerator 上的 SplitWindow (Master/Detail) 中检测 NavigationWindow 中的后退按钮单击
【发布时间】:2016-01-28 19:20:29
【问题描述】:

我有一个选项卡式应用程序(iOS - 使用 Alloy 框架),其中一个选项卡用于显示产品。在此选项卡中,我使用 SplitWindow 进行了主/详细设置。

在 Master 中,我有一个使用表格视图的简单类别浏览器。这是我的视图 xml:

<Alloy>
    <Tab title="Products" icon="Nav_Products.png" id="tabProducts" backgroundColor="white">
        <SplitWindow backgroundColor="white" showMasterInPortrait="true">

            <!-- Categories -->
            <NavigationWindow id="categoriesWindow">
                <Window title="Categories">
                    <TableView id="categories" separatorStyle="Titanium.UI.iPhone.TableViewSeparatorStyle.SINGLE_LINE" />
                </Window>
            </NavigationWindow>

            <!-- Products -->
            <NavigationWindow>
                <Window id="resultsWindow" title="Select a category to browse it's products" backgroundColor="white">
                    <RightNavButton>
                        <Button right="0" id="basketSubTotal" />
                    </RightNavButton>
                    <View left="10" top="10" right="10" bottom="10">
                        <TableView rowHeight="160" id="tblResults" allowsSelection="false" />
                    </View>
                </Window>
            </NavigationWindow>

        </SplitWindow>
    </Tab>
</Alloy>

当应用加载时,它会像这样呈现根类别:

如果我点击类别“HAIR”,它会加载“HAIR”中的子类别,并且标题为“Categories”的“Back”按钮显示如下:

所以,当我点击“

我想要做的是,检测何时单击后退按钮,并处理该操作。

因为目前,如果我深入到一个类别的 3 级,一切正常。但是,当我开始“返回”时,之前加载的产品仍保留在结果表中。当您退后一步导航时,我希望能够基本上重新加载结果。为了实现这一点,我需要检测何时单击导航窗口中的后退按钮。我怎样才能做到这一点?

【问题讨论】:

    标签: appcelerator appcelerator-titanium


    【解决方案1】:

    您可以监听按下后退按钮后触发的“关闭”事件。每个导航窗口控制器中的示例:

    var controller = Alloy.createController().getView();
    controller.addEventListener('close', function closed(e) {
         controller.removeEventListener('close',closed);
         [...]
    });
    $.navwindow.openWindow(controller); // .open(controller)
    

    或者,您可以监听自定义事件,该事件将在您的下一个窗口/控制器中触发

    就像...您的表控制器正在等待侦听事件,例如 'need_refresh'

    Ti.App.addEventListener('need_reload', function() {
        loadNewContent();
    });
    

    您可以使用fireEvent 以编程方式触发某些逻辑

    Ti.App.fireEvent('need_reload');
    

    然后,当用户按下后退按钮时,您的表格已经刷新。

    希望对你有帮助:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-10
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      • 1970-01-01
      • 2011-09-15
      • 2015-05-22
      • 2013-09-01
      相关资源
      最近更新 更多