用多个StoryBoard构建工程

一 重新创建Home、Search和About三个StoryBoard

图例1

图例2

图例3

二 创建TabBarViewController类继承于UITabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];

    //第一个 首页
    UINavigationController *homeNav = [[UIStoryboard storyboardWithName:@"Home" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
    UITabBarItem *homeItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:0];
    homeNav.tabBarItem = homeItem;
    homeNav.title = @"首页";

    //第二个 主页
    UINavigationController *searchNav = [[UIStoryboard storyboardWithName:@"Search" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
    UITabBarItem *searchItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemSearch tag:0];
    searchNav.tabBarItem = searchItem;
    searchNav.title = @"搜索";

    //第三个 关于
    UINavigationController *aboutNav = [[UIStoryboard storyboardWithName:@"About" bundle:[NSBundle mainBundle]] instantiateInitialViewController];
    UITabBarItem *aboutItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
    aboutNav.tabBarItem = aboutItem;
    aboutNav.title = @"关于";

    // 将视图控制器添加至数组中
    NSArray *viewControllers = @[homeNav,searchNav,aboutNav];
    self.viewControllers = viewControllers;
}

三 为每个Storyboard添加Storyboard Entry Point

运行工程时发现报错那是因为没有为每个Storyboard添加Storyboard Entry Point,按照下面的步骤操作即可。

图例1

图例2

四 从一个StoryBoard的某一个视图push到另一个StoryBoard的某一个视图

图例6

- (IBAction)storyboardToAbout:(id)sender
{
    UIStoryboard *story = [UIStoryboard storyboardWithName:@"About" bundle:nil];
    AboutViewController *vc = [story instantiateViewControllerWithIdentifier:@"VC"];

    [self.navigationController pushViewController:vc animated:YES];
}

最终的效果图
图例7

完整项目代码下载
官方Storyboard例子下载

五 参考

iOS storyboard 添加Entry point

在 “用多个StoryBoard构建工程” 上有 47 条评论

  1. I am really impressed with your writing skills and also with
    the layout on your blog. Is this a paid theme or did you customize it yourself?
    Either way keep up the nice quality writing, it’s rare to
    see a nice blog like this one these days.

  2. Hi this is kinda of off topic but I was wanting to know if blogs use WYSIWYG editors or if you have to manually code with
    HTML. I’m starting a blog soon but have no coding
    knowledge so I wanted to get advice from someone with experience.

    Any help would be enormously appreciated!

  3. Hey this is somewhat of off topic but I was wanting to know if blogs use WYSIWYG
    editors or if you have to manually code with HTML. I’m starting a blog soon but have no coding knowledge
    so I wanted to get advice from someone with experience.

    Any help would be enormously appreciated!

  4. We’re a group of volunteers and starting a new scheme in our community.
    Your web site offered us with valuable information to work on. You have done
    an impressive job and our entire community will be grateful to you.

  5. Helpful info. Fortunate me I discovered your website unintentionally, and I’m
    shocked why this accident did not happened earlier!
    I bookmarked it.

  6. best colleges for medical school acceptance cheapest basic health insurance
    [url=http://northwestpharmacycanadian.com/]canadian pharmacy[/url]
    individual health insurance policy

发表评论

电子邮件地址不会被公开。 必填项已用*标注