如何创建和管理嵌套的 TabbedViewNavigator? [英] How to create and manage a nested TabbedViewNavigator?

查看:29
本文介绍了如何创建和管理嵌套的 TabbedViewNavigator?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实现嵌套的 TabbedViewNavigator(在视图中).我按照这篇文章中描述的方法 3 做到了这一点:

I'm trying to implement a nested TabbedViewNavigator (inside a View). I did this by following method 3 described in this post:

Flex - 如何制作选项卡式面板

代码在这里:

<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">

<s:TabbedViewNavigator width="100%" height="100%">
    <s:ViewNavigator label="1st Tab" width="100%" height="100%" 
                     firstView="views.FirstTabView"/>
    <s:ViewNavigator label="2nd Tab" width="100%" height="100%" 
                     firstView="views.SecondTabView"/>
    <s:ViewNavigator label="3rd Tab" width="100%" height="100%" 
                     firstView="views.ThirdTabView"/>
</s:TabbedViewNavigator>

但是,如果我在其中一个子视图中调用navigator.pushView(someView)" - 假设 FirstTabView - 新视图将被推入嵌套的 TabbedViewNavigator 而不是父视图导航器.那不是我想要的.我想完全改变应用程序状态并显示一个新视图.我怎样才能做到这一点?我是否应该(在主视图中)监听嵌套 TabbedViewNavigator 中的更改,然后从那里推送新视图?还是我应该以其他方式这样做?

However if I call "navigator.pushView(someView)" inside one of the child views - let's say FirstTabView - the new view will be pushed into the nested TabbedViewNavigator instead of the parent's view navigator. That is not what I want. I want to completely change the application state and show a new view. How can I achieve that? Should I listen (in the main view) for changes within the nested TabbedViewNavigator and then push the new view from there? Or should I just do this some other way?

推荐答案

我通过使用自定义事件解决了它(它是自定义的,因为我需要从中获取数据).

I solved it by using a custom event (it's custom because I need to get data from it).

向 TabbedViewNavigator 添加了一个侦听器和一个处理程序.该事件是从活动的 ViewNavigator 视图内部调度的.该事件具有 bubbles=true 以便它上升到事件链的顶部.然后只需在事件处理程序中推送新视图.

Added a listener and a handler to the TabbedViewNavigator. The event is dispatched from inside the active ViewNavigator view. The event has bubbles=true so that it goes up to the top of the event chain. Then just push the new view in the event handler.

主视图:

    <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">

         (...)

         private function setup(){
              tabbed_panel.addEventListener(CustomEvent.BUTTON_PRESSED, eventHandler); 
         }

         private function eventHandler(ev:CustomEvent):void{
             navigator.pushView(MyNewView,ev.event_data);
         }

         (...)


         <s:TabbedViewNavigator id="tabbed_panel" width="100%" height="100%">
             <s:ViewNavigator label="1st Tab" width="100%" height="100%" 
                 firstView="views.FirstTabView"/>
             <s:ViewNavigator label="2nd Tab" width="100%" height="100%" 
                 firstView="views.SecondTabView"/>
         </s:TabbedViewNavigator>

        (...)
    </s:View>

FirstTabView:

    <View...>

         (...)

         private function buttonClickedHandler(event:Event):void{
             dispatchEvent(new CustomEvent(event_data,"BUTTON_PRESSED",true));
         }

         (...)

    </View>

我不知道这是否是解决问题的正确方法,但它有效.

I don't know if this is a corrrect approach to the problem, but it works.

这篇关于如何创建和管理嵌套的 TabbedViewNavigator?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆