开发者

Flex TabNavigator: When screen is left and returned, selectedChild is set, but tab bar highlights wrong tab

I have a TabNavigator that has a handful of children. The flow of the application allows the possibility of a user leaving the screen with this TabNavigator, then returning. When this happens, a method called on show of the parent canvas sets selectedChild to the first tab. When actually tested, the TabNavigator returns showing the text on the first tab, but the tab that is highlighted is whatever tab the user was on just before leaving.

Here is some pseudo-code that looks something like what I have:

<mx:Canvas show="init()">
<mx:Script>
<![CDATA[
    private function init():void {
        menutabs.selectedChild = tab1;
    }
 ]]>
</mx:Script>
<mx:TabNavigator id="menutabs">
    <mx:VBox id="tab1" label="Tab 1"><mx:Label text="First Tab Text" /></mx:VBox>
    <mx:VBox id="tab2" label="Tab 2"><mx:Label text="Second Tab Text" /></mx:VBox>
    <mx:VBox id="tab3" label="Tab 3"><mx:Label text="Third Tab Text" /></mx:VBox>
</mx:TabNavigator>
</mx:Canvas>

So what I am experiencing, for example, is going to 开发者_如何学编程another canvas with the application, having been on Tab 2, then returning to this canvas to see the text "First Tab Text" but the highlighted tab along the top is "Tab 2." I have tried handfuls of variations within the init() method of invalidateDisplayList, validateNow, and so on, with no change in the outcome.

Any ideas welcome.


This is the same issue seen in this question I have also been suffering from the same problem and it appears to be a bug in the Flex framework's TabNavigator control. I have yet to find the solution though.

I have managed to find a temporary workaround:

  • TabNavigator's parent, referred to as The Parent, should dispatch an additional hide event on the TabNavigator when The Parent's visibility is set to false and dispatches the hide event on The Parent. This will trigger the redrawing of the control which eliminates overlapping content areas.
  • The Parent should reset TabNavigator selectedIndex to 0 in the hide handler for The Parent.
  • If you are having issues with TabNavigator tab styling when visibility changes, you can use tabNavigator.notifyStyleChangeInChildren('tabStyleName',false) in the show handler for the tabNavigator to redraw the tab styles correctly.

I hope these are sufficient to cover your cases.


Did you observe that 'selectedChild' is an actual property of ViewStack, and not TabNavigator? Since TabNavigator can be considered as ViewStack + TabBar, setting selectedChild has no effect on TabBar.

I suggest to use 'selectedIndex' than to set selectedChild. You can obtain the selectedIndex from the Container itself, using getChildIndex()


I left out a bit of information. My init() method does more than just selectedChild, and I think this other stuff, that didn't necessarily need to run every time, was what was screwing up the re-drawing of the tabs. So I created a new goHomeTab() method to call on show, and call my init() method only on initialize. All seems to be fine now. Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜