“This is the 28th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

On the Storyboard

Storyboard is a new feature that was first introduced in iOS5, allowing developers to drastically reduce the time it takes to build an App’s user interface

About how storyboards load

  • Normally, after creating a new project, we’ll see that Xcode loads the Storyboard by default, but in real development, we’re more likely to create our own Storyboard, so here’s how we load the Storyboard when we manually create the controller

  • Usually in a new project, we first remove the Xcode loading Storyboard

  • About the Storyboard creation controller

    The first:

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [sb instantiateInitialViewController];
    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];
    Copy the code

    The second:

    self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"WAKAKA"];
    self.window.rootViewController = vc;
    [self.window makeKeyAndVisible];
    Copy the code

About UIStoryboardSegue

In storyboards, the lines that describe the interface are all UIStoryboardSegue objects.

The properties of Segue

  • Unique Identifier
  • Source Controller (sourceViewController)
  • The target controller (destinationViewController)

The type of the Segue

  • Automatic (click on a control, without some judgment can jump directly)

  • Manual (clicking on a control requires some judgment before jumping)

  • Setting up segues manually requires setting

    Perform the corresponding Segue using the Perform method

    // Find the corresponding line in the storyboard according to the Identifier, then create a storyboard object
                [self performSegueWithIdentifier:@"showinfo" sender:nil];
    Copy the code

    If you need to do a value transfer or jump to a different UI, you need to code it in this method

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
        // Compare unique identifiers
        if ([segue.identifier isEqualToString:@"showInfo"]) {
            // Source controller
            UINavigationController *nvc = segue.sourceViewController;
            // Destination controller
            ListViewController *vc = segue.destinationViewController;
            vc.info = @"show"; }}Copy the code