2013-10-09 60 views
0

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

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

回答

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]; 
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) { 
    }]; 
}