Use of UITabBarController

update record

time Revision
April 19, 2020 First edition

Foreword

  • The main interface of many apps in iOS is controlled by a tabBar, which controls multiple main interfaces. For example, in WeChat, there are 4 TabBarItems on the main interface, corresponding to "chat", "address book", "discovery", and "mine".
  • For iOS apps, it is likely that the rootViewController of the app is a custom subclass of UITabBarController.
  • So it is very likely that the processing of the entire business of the app will be placed in such a class.

Related knowledge points of UITabBarController

UITabBarController

  • This class has an attribute:
    • @property(nullable, nonatomic,copy) NSArray<__kindof UIViewController *> *viewControllers;
    • After initializing this property, the tabBarItem in UITabBarController corresponds to this VC array.
  • By default, item 0 of the array is selected.
  • The clicked tabBarItem, the corresponding VC will not be loaded.
  • The clicked tabBarItem, its corresponding VC resident memory, will not be destroyed.

UITabBarControllerItem

  • UIViewController has a category calledUIViewController (UITabBarControllerItem)
  • So every custom VC class that inherits from UIViewController (which is also a hidden rule in iOS, custom VC must inherit from UIViewController) has the ability to become a TabBarItem held by UITabBarController.
    • Remember the benefits of classification mentioned in "Objective-C Basic Tutorial"? One of them is that you can disperse different codes of classes into different scopes. In this example, you can put the code about the use of Tab in UIViewController specifically in the file UITabBarController.h for management.
  • Later, you can change the UITabBarItem property of the VC to correspond to the behavior of the tabBarItem corresponding to the VC (such as the title of the tabBarItem, icon, etc.)

UITabBarControllerDelegate

  • It is mainly used to customize some response times. For example, select the tabBar event.

Guess you like

Origin www.cnblogs.com/HelloGreen/p/12735178.html
use
use