一,创建静态类库为了别人调用,于是最好的入口应该是单例,下面是比较好的一种写法
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class HWeatherManager;
@protocol HWeatherManagerDelegate <NSObject>
//使用代理向外传值
- (void)test:(NSString *)str;
@end
//实现
@interface HWeatherManager : NSObject
@property (nonatomic ,strong) UIViewController<HWeatherManagerDelegate> *delegate;
+ (HWeatherManager *)defaultManager;
- (void)start;
@end
#import "HWeatherManager.h"
@implementation HWeatherManager
+ (HWeatherManager *)defaultManager
{
static HWeatherManager *s_HWeatherManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if (s_HWeatherManager == nil) {
s_HWeatherManager = [[HWeatherManager alloc] init];
}
});
return s_HWeatherManager;
}
- (void)start
{
[self.delegate test:@"hello"];
NSBundle *bundle=[NSBundle bundleWithURL:[[NSBundle mainBundle]URLForResource:@"HWeatherDataLibResources" withExtension:@"bundle"]];
UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"WeatherStoryboard" bundle:bundle];
//instantiateInitialViewController就是navigationController,调用之后将直接显示根视图控制器的视图
[self.delegate presentViewController:[storyboard instantiateInitialViewController] animated:YES completion:^{
}];
}
@end
在类库的根视图控制器下,主要代码:
- (void)viewWillAppear:(BOOL)animated//此处经典!可以解决bar在本页显示不影响其他页面
{
[super viewWillAppear:animated];
[self.navigationController.navigationBar setHidden:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[self.navigationController.navigationBar setHidden:NO];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSBundle *bundle=[NSBundle bundleWithURL:[[NSBundle mainBundle]URLForResource:@"HWeatherDataLibResources" withExtension:@"bundle"]];
.....other content....
}
//这里使用push最好
-(void)onClickSelectQu:(UIButton *)sender
{
UIViewController *qucontroller= [self.storyboard instantiateViewControllerWithIdentifier:@"qucontroller"];
[self.navigationController pushViewController:qucontroller animated:YES];
// [self performSegueWithIdentifier:@"mainToQu" sender:self];
}
问题解决总结:
使用模拟器.a //就是编译静态库的时候选ios模式下
单例作为入口 //入口最好用上面介绍的单例,我以前使用的是控制器
built setting (other link) -objc (解决不是别类的bug)在其他类中调用一下本类
[self presentViewController:controller animated:YES completion:^{
}];没有navigationBar可以显示,要换成 [self.navigationController pushViewController:qucontroller animated:YES];