2013-10-09 88 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) { 
    }]; 
}