如何装载Storyboard中的ViewController
推荐于2016-08-28 · 知道合伙人数码行家
知道合伙人数码行家
向TA提问 私信TA
首先,需要指定ViewController的ID,如上图右上方红色方框内的Storyboard ID。然后使用下面的代码:
[cpp] view plaincopyprint?
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
LeftViewController *leftController = [mainStoryboard instantiateViewControllerWithIdentifier:@"leftViewController"];
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
LeftViewController *leftController = [mainStoryboard instantiateViewControllerWithIdentifier:@"leftViewController"];
或者使用下面的代码:
[cpp] view plaincopyprint?
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
ViewController *leftController = [mainStoryboard instantiateViewControllerWithIdentifier:@"leftViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:leftController];
UIStoryboard* mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
ViewController *leftController = [mainStoryboard instantiateViewControllerWithIdentifier:@"leftViewController"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:leftController];