【问题标题】:flex mobile TabbedViewNavigatorApplication back buttonflex mobile TabbedViewNavigatorApplication后退按钮
【发布时间】:2012-02-09 22:22:50
【问题描述】:

为什么 TabbedViewNavigatorApplication 没有 popView()(如 ViewNavigatorApplication 我可以使用 popView 转到上一个视图)?

如何在 TabbedViewNavigatorApplication 中做到这一点?

    <fx:Script>
    <![CDATA[      
      protected function BackBtn(event:MouseEvent):void{
        navigator.popView(); //error
      }
    ]]>
  </fx:Script>

<s:ViewNavigator label="Page1" width="100%" height="100%" firstView="views.DurationView" >
    <s:titleContent>
      <s:Button label="Back" click="BackBtn(event)"/>
    </s:titleContent>
  </s:ViewNavigator>
<s:ViewNavigator label="Page2" width="100%" height="100%" firstView="views.FrequencyView"/>
</s:TabbedViewNavigatorApplication>

谢谢。

【问题讨论】:

  • 什么是错误... //错误与分段错误一样好:)
  • 错误是:“未定义属性导航器的访问”
  • Navigator 因此是不是选项卡对象的属性是 selectedIndex 可用?您可能需要创建一个数组来存储导航历史记录并推送/弹出数组读取或写入 selectedIndex。目前在移动设备上,但我会尝试验证。
  • 嗯,看起来 selectedIndex 应该可以工作help.adobe.com/en_US/flex/mobileapps/…
  • 我认为我缺少一个基本问题。在选项卡式应用程序中; Flex 是如何知道您想要返回的内容的?在 ViewNavigatorApplication 中,您必须显式推送视图。我认为在选项卡式应用程序中,您没有这样做;你在运行时定义了它们。

标签: apache-flex mobile flex4 flex4.5 flexbuilder


【解决方案1】:
<?xml version="1.0" encoding="utf-8"?>
<s:TabbedViewNavigatorApplication creationComplete="tabbedviewnavigatorapplication1_creationCompleteHandler(event)"
                                  xmlns:fx="http://ns.adobe.com/mxml/2009"
                                  xmlns:s="library://ns.adobe.com/flex/spark">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            import spark.events.IndexChangeEvent;

            private var tabHistory : Array;
            private var isLoadingFromHistory : Boolean;

            protected function BackBtn(event : MouseEvent) : void
            {
                isLoadingFromHistory = true;
                if (tabHistory.length == 0)
                {
                    trace("You can't go back any further");
                    tabHistory.push(0);
                }
                tabbedNavigator.selectedIndex = tabHistory.pop();
            }

            protected function tabbedviewnavigatorapplication1_creationCompleteHandler(event : FlexEvent) : void
            {
                tabHistory = [];
                tabbedNavigator.addEventListener(IndexChangeEvent.CHANGE, tabsChangedHandler);
            }

            private function tabsChangedHandler(event : IndexChangeEvent) : void
            {
                if (isLoadingFromHistory)
                {
                    isLoadingFromHistory = false;
                    return;
                }
                tabHistory.push(event.oldIndex);
                trace(tabHistory);
            }
        ]]>
    </fx:Script>

    <s:ViewNavigator firstView="views.WhosAtTheDoorHomeView"
                     height="100%"
                     label="Page1"
                     width="100%">
        <s:titleContent>
            <s:Button click="BackBtn(event)"
                      label="Back"/>
        </s:titleContent>
    </s:ViewNavigator>
    <s:ViewNavigator firstView="views.WhosAtTheDoorHomeViewCopy"
                     height="100%"
                     label="Page2"
                     width="100%">
        <s:titleContent>
            <s:Button click="BackBtn(event)"
                      label="Back"/>
        </s:titleContent>
    </s:ViewNavigator>
</s:TabbedViewNavigatorApplication>

【讨论】:

  • 我这里的一些逻辑可能有点笨拙,我只是把它放在一起,所以请确保你彻底测试。
  • 事实上,看这个可能你想删除带有评论的弹出窗口并只存储 event.oldIndex ......无论如何应该让你找到解决方案。
  • 感谢您的解决方案,它让我可以使用“后退”按钮从上一个选项卡返回。更进一步,在选项卡式应用程序中,一个选项卡有 2 个视图,如何移回上一个视图?例如。在同一个选项卡中从 2ndView 回到 1stView?我在link 中提出了一个新问题,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多