多个storyboard开发应用程序,封装.bundle和.a不用xib使用storyboard!!!

一,封装.bundle和.a使用xib的方式前面已经说过了,具体方式不再赘述,简单介绍于下:

静态库加.h  bundle:删plist,改sdk,加xib 简称psx三步

引用库的项目,加.a .bundle 编辑edit scheme

二,storyboard出现的比较晚,封装的教程如今全网仅此一家,方便开发!

首先创建静态库,方法都和以前的一样,就把xib换成storyBoard就行了,难就难在怎么引用上,下面介绍于下:

在跟控制器上声明一个属性一个方法,为了调用的时候更方便

//比如A控制器要跳转过来,就把A的实例赋值给此source属性然后调用 startViewController方法就可以跳转过来

@property (nonatomic,strong)UIViewController *sourceViewController;

//启动该视图控制器,显示天气视图,sourceViewController赋值之后就调用该方法

-(void)startViewController;

 然后实现方式如下:

-(void)startViewController

{

    NSBundle *bundle=[NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"WeatherDataLibResources" withExtension:@"bundle"]];

    UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"WeatherStoryboard" bundle:bundle];   

    [self.sourceViewController presentViewController:[storyboard instantiateInitialViewController] animated:YEScompletion:^{

        

    }];    

}

三,在引用的地方先引入头文件,然后实例化,设置参数,方式如下:  

WeatherViewController *weatherViewController=[[WeatherViewController alloc]init];

    weatherViewController.sourceViewController=self;

    [weatherViewController startViewController];

使用中遇到问题  Unknown class <class name> in interface Builder file.

 遇到这个问题的人一时半会解决不了这个问题,真他妈蛋疼,我弄了一天多

解决:

1,xcode优化机制制造的这个问题,在任意一个类中调用一下这个类就行,比如打log或直接[类 class];

2,在project中的link flag加  -all_load

另外一个奇葩问题

  [self.sourceViewController presentViewController:[storyboard instantiateInitialViewController] animated:YEScompletion:^{}];

这个方法可以显示视图,但是没有navigationBar!

还是直接使用push方法才能解决

在静态库中操作时经验终结:

使用模拟器.a
单例作为入口
built setting (other link) -objc  (解决不是别类的bug)
[self presentViewController:controller animated:YES completion:^{
    }];没有navigationBar可以显示,要换成 [self.navigationController pushViewController:qucontroller animated:YES];

原文地址:https://www.cnblogs.com/huntaiji/p/3490911.html