如何将故事板连接到代码

Lon*_*ith 1 xcode objective-c storyboard xib ios

我创建了空的IOS项目,并希望创建UI.我搜索了有关将故事板连接到代码的信息,但没有任何关于它,只是关于xib文件.那么有可能在空项目中使用storyboard而不是xib吗?如何?

iPr*_*abu 5

假设您已经在项目中有一个Storyboard文件,您可以获得这样的storyboard对象

    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
    YourViewController *yourVC = [storyBoard instantiateViewControllerWithIdentifier:@"identifier"];
    //Do whatever with the viewcontroller object
    [self.navigationController pushViewController:yourVC animated:YES ];
Run Code Online (Sandbox Code Playgroud)

注意:

  1. 检查故事板名称
  2. 检查Storyboard中的viewcontroller标识符

在此输入图像描述