如何裝載Storyboard中的ViewController?

 

如上圖所示,如何裝載Storyboard中指定的ViewController?app

首先,須要指定ViewController的ID,如上圖右上方紅色方框內的Storyboard ID。而後使用下面的代碼:oop

 

 

[cpp]  view plain copy
  1. UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];  
  2. LeftViewController *leftController = [mainStoryboard instantiateViewControllerWithIdentifier:@"leftViewController"];  

或者使用下面的代碼:

 

 

[cpp]  view plain copy
  1. UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];  
  2. ViewController *leftController = [mainStoryboard instantiateViewControllerWithIdentifier:@"leftViewController"];  
  3. UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:leftController];  
相關文章
相關標籤/搜索