将新的viewcontroller链接到Storyboard?

Jus*_*tin 28 xcode interface-builder uiviewcontroller ios ios5

可能有一个简单的解决方案,但我无法弄清楚.

我正在使用故事板作为界面.

我从一个标签栏控制器开始,但在允许用户使用该应用程序之前,用户必须通过在开始时以模态方式推送的登录视图来验证自己.

我想在同一个故事板上配置loginview,但我无法找到如何链接故事板上的视图控制器和我的代码.

我做了什么:

  • 通过文件>新建>新文件创建新的UIViewController子类.
  • 在故事板中拖动一个新的UIViewController
  • 在自定义类选项卡中设置类
  • 拖动UILabel用于测试目的.

无标签...

Sco*_*ood 40

拉上一个新的UIViewController,它将作为MainStoryboard上的登录视图控制器.在属性检查器中,将标识符更改为LoginViewController(或适当的内容).然后加

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];

    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"LoginViewController"];
    [vc setModalPresentationStyle:UIModalPresentationFullScreen];

    [self presentModalViewController:vc animated:YES];
}
Run Code Online (Sandbox Code Playgroud)

到第一个视图控制器和登录屏幕将从故事板加载并显示.

希望这可以帮助.

  • 我想我不明白这个问题.这是我创建的项目,如果你想快速浏览并让我知道它是否有帮助,或者如果你能澄清我的问题在哪里,我们应该能够找到解决方案.http://www.scott-sherwood.com/?attachment_id=512 (2认同)

小智 6

以上Scott Sherwood的答案是经过大量搜索后找到的最正确的答案.虽然根据新的SDK(6.1)进行了微小的更改,但presentModalViewController显示已弃用.

以上是对上述答案的极小变化.

 UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
    HomeViewController * hvc = [sb instantiateViewControllerWithIdentifier:@"LoginView"];
    [hvc setModalPresentationStyle:UIModalPresentationFullScreen];
    [self presentViewController:hvc animated:YES completion:nil]; 
Run Code Online (Sandbox Code Playgroud)