如上图所示,如何装载Storyboard中指定的ViewController?

首先,需要指定ViewController的ID,如上图右上方红色方框内的Storyboard ID。然后使用下面的代码:


[cpp]view plaincopy UIStoryboard*mainStoryboard=[UIStoryboardstoryboardWithName:@"MainStoryboard_iPhone"bundle:nil]; LeftViewController*leftController=[mainStoryboardinstantiateViewControllerWithIdentifier:@"leftViewController"];
或者使用下面的代码:

[cpp]view plaincopy UIStoryboard*mainStoryboard=[UIStoryboardstoryboardWithName:@"MainStoryboard_iPhone"bundle:nil]; ViewController*leftController=[mainStoryboardinstantiateViewControllerWithIdentifier:@"leftViewController"]; UINavigationController*navController=[[UINavigationControlleralloc]initWithRootViewController:leftController];