Call a view controller programatically using storyboard id iOS

后端 未结 3 830
离开以前
离开以前 2021-01-22 00:10

What I Want?

  • In MainViewController I open a view from a xib programmatically. This xib view contains a UIButton. The xib opens successf
3条回答
  •  星月不相逢
    2021-01-22 00:54

    whenever you want to load a VC as the way you mentioned, you need two things.

    Thing 1: Specific storyboard ID. you will find this by:

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Your_Storyboard_Id" bundle:nil];

    In my case this is Main

    Thing 2:

    You need your View Controller id. Just click on the View Controller you want to go from storyboard and give a suitableName there.

    Then invoke this like:

    UIViewController * yourVC = [storyboard   
    instantiateViewControllerWithIdentifier:@"YourVC_ID"] ;
    

    And if you want to present it modally you already did this. :)

    [self presentViewController:yourVC animated:YES completion:nil];
    

提交回复
热议问题