StoryBoard is an intuitive development tool for iOS development and can greatly improve development efficiency, but StoryBoard can also cause problems because it can directly describe multiple controller pages.

When the team is developing, dragging too many controllers into the StoryBoard can lead to a complex interface. And collaborative development is especially prone to conflict. Conflicts can also be particularly difficult to resolve if they occur, and connections can directly affect troubleshooting.

Apple is aware of the problem. A StoryBoard Reference feature was introduced in iOS 9. That’s a good solution to the problem.

StoryBoard Reference

introduce

StoryBoard Refrence is what a StoryBoard reference is, and it provides a placeholder controller for other storyboards

use

It is very simple to use: tabbarController –> navigationController –> viewController structure, but more since the controller is messy, also difficult to debug. So you can extract each self-control module separately to create a separate StoryBoard.

Operating as follows

The figure converts the corresponding module into a new StoryBoard and generates a StoryBoard Reference in the original section. The effect is very intuitive!That’s going to generate a couple of new storyboards. The StoryBoard is a separate part of each module, which not only makes it more intuitive, but also eliminates many security risks.

So the new StoryBoard is going to create the ViewController directly from the StoryBoard to set up the UI page.

summary

  • 1.StoryBoard Reference is easy to use and solves the problem that storyboards are too large to maintain.
  • 2.StoryBoard Reference is a new feature after iOS 9. If you use it directly, the system version will not be available for models with iOS 9 or later
  • 3. Do the following adaptation for iOS 9: The corresponding StoryBoard Reference can be deleted and the ViewController in the corresponding StoryBoard can be loaded through code based on the generated new StoryBoard.

Update actual operations

  • Add a TabbarViewController to main. storyboard and remove the original ViewController entry arrow points to TabBarVC and assigns it to MainViewController
  • Add one item plus one NavigationController arrow points past set to Controllers add more

Start operation (key point)

  • Select both Navi and root ->Editor->Refactor to Storyboard

  • After each operation, the structure is clear

expand

Now this main.storyboard still has a few lines and a few scenes and it’s still annoying

  • 1. Unconnect mainViewcontroll, right-click mainViewcontroll and click X to delete four StoryBoard references

  • 2. Add code to MainViewController
import UIKit class MainViewController: UITabBarController { override func viewDidLoad() { super.viewDidLoad() addChildVc("Home") addChildVc("Rank") addChildVc("Discover") addChildVc("Profile") } fileprivate func addChildVc(_ storyName : String) { // 1. Let the storyboard for controller childVc = UIStoryboard (name: storyName, bundle: nil). InstantiateInitialViewController ()! AddChild (childVc)}}Copy the code
  • Notice that you have to write the names right or you’re not going to be able to do this because there’s no need to add code to this step and it’s going to be even more boring

Add the TabItem image and modify the Title