简体   繁体   English

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

[英]How do I load a nib file through storyboard?

I'm trying to load a particular scene from storyboard dynamically using it's story board id. 我正在尝试使用情节提要ID从情节提要动态加载特定场景。 It is more like loading a separate nib file through storyboard. 这更像是通过情节提要加载单独的笔尖文件。 I have a scene with a storyboard id "storyid". 我有一个情节提要ID为“ storyid”的场景。 Then I'm trying to load it but unable get that scene on my screen when it is loaded. 然后,我尝试加载它,但是加载时无法在屏幕上显示该场景。 I get no errors in the code. 我在代码中没有错误。

- (IBAction)btnLoadSceneClicked:(id)sender
{
    NSLog(@"btnLoadSceneClicked");
    [self.storyboard instantiateViewControllerWithIdentifier:@"storyid"];
}
YourViewControllerClass * viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"storyid"];
[self presentViewController: animated:YES completion:^{ /* what happens when the viewController is presented */}]

You could also push the viewController if you are embedded in a navigation controller. 如果您嵌入在导航控制器中,也可以推送viewController。

[self.navigationController pushViewController:viewController animated:YES];
- (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) {
    }];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM