Creating a segue programmatically

前端 未结 13 1098
名媛妹妹
名媛妹妹 2020-11-22 12:41

I have a common UIViewController that all my UIViewsControllers extend to reuse some common operations.

I want to set up a segue on this \"

13条回答
  •  Happy的楠姐
    2020-11-22 13:17

    First of, suppose you have two different views in storyboard, and you want to navigate from one screen to another, so follow this steps:

    1). Define all your views with class file and also storyboard id in identity inspector.

    2). Make sure you add a navigation controller to the first view. Select it in the Storyboard and then Editor >Embed In > Navigation Controller

    3). In your first class, import the "secondClass.h"

    #import "ViewController.h
    #import "secondController.h"
    

    4). Add this command in the IBAction that has to perform the segue

    secondController *next=[self.storyboard instantiateViewControllerWithIdentifier:@"second"];
    [self.navigationController pushViewController:next animated:YES];
    

    5). @"second" is secondview controller class, storyboard id.

提交回复
热议问题