UITabBarController如何适应VIPER架构? [英] How a UITabBarController fit into the VIPER architecture?

查看:112
本文介绍了UITabBarController如何适应VIPER架构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个具有基于TabBar的导航的应用程序。我正在采用VIPER架构但我真的很困惑如何实现UITabBarController的标签更改。

I am writing an application which has a TabBar based navigation. I am adopting the VIPER architecture but I am really confused with the topic of how a UITabBarController's tab changing should be implemented.

推荐答案

这个可能会迟到,但对其他人可能会有所帮助。
我的用例是在登录界面后实现tabBarController。
我们可以通过很多方式在VIPER中完成它,但我是如何做到的,如下所示:

This might be late, but it might be helpful for others. My use case was to implement the tabBarController after the login screen. There can be many ways we can do it in VIPER but how I did it is as follows:


  1. 手动分配TabBar,不使用故事板。

  2. 仅为TabBarWireframe演示创建一个新的WireFrame类。

  3. 创建一个包含一个可变数组的单例类,该数组将包含所有视图要分配给tabBarController的控制器。

  4. 创建一个json文件,它将为我提供选项卡的值,可以跳过此步骤,因为我希望选项卡基于来自JSON文件的值是动态的。如果您有静态标签,请跳过此步骤。

  5. 在TabBarWireframe中,放置一个调用所有标签线框的循环。

  6. 在您的各个线框中实例化viewController obj并将其添加到我们在步骤3中创建的单例类数组中。

  7. 所有作为制表符一部分的viewController都是数组的一部分。只需从loginviewcontroller实例中呈现tabBar控制器(它的实例只是将方法传递给tabBarWireframe类)。

  1. Allocated TabBar manually, without using storyboards.
  2. Create a new WireFrame class only for TabBarWireframe presentation.
  3. Create a singleton class with one mutable array which will contain all the view controllers to be assigned to the tabBarController.
  4. Create a json file which will provide me the values of tabs, This step can be skipped as I wanted tabs to be dynamic based on value from JSON file. If u have static tabs skip this step.
  5. In TabBarWireframe, put a loop which call all your tabs wireframes.
  6. In your individual wireframes just instantiate the viewController obj and add it to the singleton class array we created in step 3.
  7. After all viewController which are part of tabs are part of the array. Just present the tabBar Controller from the loginviewcontroller instance(Its instance just pass through a method to the tabBarWireframe class).

希望我有意义。

这篇关于UITabBarController如何适应VIPER架构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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