如何通过故事板加载nib文件?

时间:2013-10-09 06:16:31

标签: ios objective-c

我正在尝试使用它的故事板ID动态加载故事板中的特定场景。它更像是通过故事板加载单独的nib文件。我有一个故事板ID“storyid”的场景。然后我正在尝试加载它但在加载时无法在我的屏幕上获得该场景。我在代码中没有错误。

- (IBAction)btnLoadSceneClicked:(id)sender
{
    NSLog(@"btnLoadSceneClicked");
    [self.storyboard instantiateViewControllerWithIdentifier:@"storyid"];
}

2 个答案:

答案 0 :(得分:2)

YourViewControllerClass * viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"storyid"];
[self presentViewController: animated:YES completion:^{ /* what happens when the viewController is presented */}]

如果嵌入在导航控制器中,也可以推送viewController。

[self.navigationController pushViewController:viewController animated:YES];

答案 1 :(得分:0)

- (IBAction)btnLoadSceneClicked:(id)sender
{
    NSLog(@"btnLoadSceneClicked");
     YourViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"storyBoardID"];
    [viewController.view setFrame:CGRectMake(160, 0, self.view.frame.size.width, self.view.frame.size.height)];
    [self.view addSubview:viewController.view];
    [UIView animateWithDuration:0.50f animations:^{
        [viewController.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    } completion:^(BOOL finished) {
    }];
}