用多个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

47 thoughts to “用多个StoryBoard构建工程”

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

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

发表评论

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