2012-02-09 37 views
0

爲什麼TabbedViewNavigatorApplication沒有popView()(如ViewNavigatorApplication我可以用popView去以前的觀點)?Flex移動TabbedViewNavigatorApplication後退按鈕

我該怎麼做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> 

謝謝。

+0

什麼是錯誤... //誤差大約是分段錯誤:) – shaunhusain 2012-02-09 22:31:55

+0

錯誤是一樣好: – jameslcs 2012-02-09 22:51:29

+0

導航「的未定義的屬性導航訪問」因此不是標籤對象的屬性是selectedIndex可用?您可能需要創建一個數組來存儲導航歷史記錄以及從讀取或寫入selectedIndex的數組上讀取/彈出數組。現在在手機上,但我會嘗試驗證。 – shaunhusain 2012-02-09 23:20:59

回答

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> 
+0

這裏我的一些邏輯可能會有點珍貴,我只是把它扔在一起,所以確保你徹底的測試。 – shaunhusain 2012-02-10 00:02:32

+0

事實上,看着這個也許你想刪除流行與它的評論,只是存儲event.oldIndex相反......無論如何應該讓你走向一個解決方案。 – shaunhusain 2012-02-10 00:04:16

+0

感謝您的解決方案,它讓我從前一個Tab返回按鈕。 更進一步,在標籤的應用程序中,一個選項卡有2個視圖,如何移回到以前的視圖?例如。從2ndView回到同一個Tab中的1stView?我在這個[鏈接](http://stackoverflow.com/questions/9235784/flex-mobile-tabbedviewnavigatorapplication-back-button-part2) 謝謝你提出一個新的問題。 – jameslcs 2012-02-10 22:40:24