简体   繁体   English

查看导航器隐藏特定选项卡而非TabBar

[英]View Navigator Hide Specific Tab Not TabBar

I'm trying to figure out whether it is possible to define view navigators and selectively hide some depending on a particular user state? 我试图弄清楚是否可以定义视图导航器并根据特定的用户状态有选择地隐藏一些导航器?

For example I have two navigator tabs one which is a sign in tab and the other shows a users policy. 例如,我有两个导航器选项卡,一个是登录选项卡,另一个显示了用户策略。 I only want the policy tab to be visible if the user has signed in: 如果用户已登录,我只希望策略选项卡可见:

<s:ViewNavigator id="policyTab" width="100%" height="100%" firstView="views.policy.PoliciesView">
    <s:navigationContent>
        <s:Button id="policyTabButton" label="Policies" click="tabButton_clickHandler(event)" />
    </s:navigationContent>
</s:ViewNavigator>

Sign in tab is navigator: 登录标签是导航器:

<s:ViewNavigator id="signInTab" width="100%" height="100%" firstView="views.SignInView">
    <s:navigationContent>
        <s:Button id="signInTabButton" icon="@Embed('images/lockSmall.png')" click="tabButton_clickHandler(event)" />
    </s:navigationContent>
</s:ViewNavigator>  

Everything that I've researched points me to hiding the entire tab bar which I don't want to do. 我研究的所有内容都指向隐藏整个标签栏,这些标签栏我我不想做。 I've tried simply calling signInTab.visible = false; 我试过简单地调用signInTab.visible = false;。 but is doesn't work. 但是是行不通的。

Any help would be appreciated. 任何帮助,将不胜感激。

It is true that you can't hide the contents of a TabbedViewNavigator, but there is another way to adjust the content to hide tabs. 的确,您无法隐藏TabbedViewNavigator的内容,但是还有另一种方法来调整内容以隐藏选项卡。 Basically you can remove the tab from the TabbedViewNavigator to hide it and re-add it to show it again. 基本上,您可以从TabbedViewNavigator中删除该选项卡以将其隐藏并重新添加以再次显示它。 I've come up with a very simple example which seems to do what you are asking. 我提出了一个非常简单的示例,它似乎可以满足您的要求。

TabbedViewNavTest.mxml: TabbedViewNavTest.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:TabbedViewNavigatorApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                                  xmlns:s="library://ns.adobe.com/flex/spark"
                                  applicationDPI="160"
                                  preinitialize="preinitializeHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            import views.Tab2View;

            private static var app:TabbedViewNavigatorApplication;

            public static function adjustTabBar():void {
                if(app.navigators.length > 1) {
                    removeTab2();
                } else {
                    addTab2();
                }
            }

            private static function removeTab2():void {
                app.tabbedNavigator.removeItemAt(1);
            }

            private static function addTab2():void {
                var tab2:ViewNavigator = new ViewNavigator();
                tab2.label = "Tab2";
                tab2.percentWidth = 100;
                tab2.percentHeight = 100;
                tab2.firstView = Tab2View;
                app.tabbedNavigator.addItemAt(tab2, 1);
            }

            protected function preinitializeHandler(event:FlexEvent):void {
                app = this;
            }

        ]]>
    </fx:Script>

    <s:ViewNavigator id="tab1" label="Tab1" width="100%" height="100%" firstView="views.Tab1View"/>
    <s:ViewNavigator id="tab2" label="Tab2" width="100%" height="100%" firstView="views.Tab2View"/>

</s:TabbedViewNavigatorApplication>

Tab1View.mxml: Tab1View.mxml:

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
        xmlns:s="library://ns.adobe.com/flex/spark"
        title="Tab1">

    <fx:Script>
        <![CDATA[
            protected function showHideButton_clickHandler(event:MouseEvent):void {
                TabbedViewNavTest.adjustTabBar();
            }
        ]]>
    </fx:Script>

    <s:Button id="showHideButton" label="Click Me!" click="showHideButton_clickHandler(event)" />
</s:View>

Tab2View is just an empty view that was created when I created the project. Tab2View只是我创建项目时创建的一个空视图。

While this should do what you need it to do, I'm wondering if there is a better way to achieve what you are attempting to do. 尽管这应该可以完成您需要做的事情,但我想知道是否有更好的方法来实现您要尝试做的事情。 For instance, in the case you originally presented of a login tab which disappears when the user logs in you could have created your application as a generic application with 2 states: notLoggedIn and loggedIn. 例如,如果您最初显示的是一个登录选项卡,当用户登录时该选项卡消失了,则可以将您的应用程序创建为具有以下两种状态的通用应用程序:notLoggedIn和loggingIn。 In the notLoggedIn state you only have a view show that presents the login screen, or have a tabbedViewNavigator show which has the login and policy tabs. 在notLoggedIn状态下,您只能看到一个显示登录屏幕的视图,或者一个带有登录和策略选项卡的tabbedViewNavigator显示。 In the logged in state, you have a separate tabbedViewNavigator which has only the policy tab or perhaps the other tabs available when a user is logged in. If you want me to create an example of what I mean, let me know and I can do that. 在登录状态下,您有一个单独的tabbedViewNavigator,其中只有策略选项卡,或者在用户登录时可能具有其他选项卡。如果要我创建我的意思的示例,请告诉我,我可以做那。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM