首页 > 代码库 > IOS中用UIStoryBoard类初始化/跳转控制器

IOS中用UIStoryBoard类初始化/跳转控制器

1.空工程中通过创建storyboard文件加载页面


//获取Main.storyboard
   
UIStoryboard*mainStory = [UIStoryboardstoryboardWithName:@"Main"bundle:nil];
//获取Main.storyboard中的第2个视图
   
SecondViewController*secondController = [mainStory instantiateViewControllerWithIdentifier:@"SecondStory"];
//设置窗体的根视图为Storyboard里的视图
   
self.window.rootViewController= secondController

StoryBoard的ID在这里设置:

技术分享


2. 其他控制器中设置StoryBoard的初始控制器为window的根控制器

UIStoryboard *stotyb = [UIStoryboard storyboardWithName:@"Second" bundle:nil];
    [self.view.window setRootViewController:stotyb.instantiateInitialViewController];

3.跳转到Storyboard中某个控制器

//获取Main.storyboard
   
UIStoryboard*mainStory = [UIStoryboardstoryboardWithName:@"Main"bundle:nil];

 //获取Main.storyboard中的第2个视图
   
SecondViewController*secondController = [mainStory instantiateViewControllerWithIdentifier:@"SecondStory"];
//跳转页面

    [selfpresentViewController:secondControlleranimated:YEScompletion:nil];


 

IOS中用UIStoryBoard类初始化/跳转控制器