【问题标题】:nativescript tabview actionbar nestednativescript tabview 操作栏嵌套
【发布时间】:2018-07-26 07:44:53
【问题描述】:

我有 4 个选项卡,我在每个选项卡中使用路由器插座进行“导航”。 我想问你是否可以为每个选项卡创建不同的操作栏,是否可以在选项卡内导航,同时更改操作栏的标题和项目

【问题讨论】:

    标签: navigation nested android-actionbar nativescript tabview


    【解决方案1】:

    您不能为每个标签保留单独的操作栏,但您可以尝试在标签之间切换时更新操作栏。

    【讨论】:

      【解决方案2】:

      我通过为四个选项卡的每个组件创建一个操作栏并根据所选选项卡在所需选项卡中导航来解决,例如:

      public onIndexChanged(args) {
          let tabView = <TabView>args.object;
          if(tabView.selectedIndex == 0){
              this.title = this.test;
              this.routerExtensions.navigate(['tabs',
                  {
                      outlets: {'test': ['test'],
                  }
              }], { 
                  clearHistory: true 
               });
          }
          else if(tabView.selectedIndex == 1){
              this.title = this.test1;
              this.routerExtensions.navigate(['tabs',
                  {
                      outlets: {'test1': ['test1'],
                  }
              }], { clearHistory: true });
          }
          else if(tabView.selectedIndex == 2){
              this.title = this.test2;
              this.routerExtensions.navigate(['tabs',
                  {
                      outlets: {'test2': ['test2'],
                  }
              }], { clearHistory: true });
          }
          else if(tabView.selectedIndex == 3){
              this.title = this.notifications;
              this.routerExtensions.navigate(['tabs',
                  {
                      outlets: {'test3': ['test3'],
                  }
              }], { clearHistory: true });
          }
          else if(tabView.selectedIndex == 4){
              this.title = this.settings;
              this.routerExtensions.navigate(['tabs',
                  {
                      outlets: {'test4': ['test4'],
                  }
              }], { clearHistory: true });
          }
      }
      

      然后在每个选项卡中我都有其他操作栏的其他视图。更改选项卡时,历史记录会被取消,因此如果我返回之前打开的选项卡,则会重新创建它,然后再次更新操作栏。

      我发现的唯一问题(我认为这是一个错误)是(在 android 上)删除 router-outlet 的历史记录不起作用。

      编辑

      我必须传递一个随机参数以允许我要离开的组件调用 OnDestroy 方法,这样当我返回离开它的选项卡时,它会重新创建包括操作栏在内的所有内容

      this.routerExtensions.navigate(['tabs',
              {
                parameterForOnDestroy: true
              },
              {
                  outlets: {'test': ['test'],
              }
          }], { 
              clearHistory: true 
           });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-27
        • 2020-06-25
        • 1970-01-01
        • 2017-05-12
        • 2019-02-16
        相关资源
        最近更新 更多