IOS源码封装成.bundle和.a文件时,使用单例作为出口的写法!任何封装都建议使用这种方法作为出口
头文件
以此作为模板,记录于此
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
//this can write delegate directly,but out of the class ,can't see the class,so we add a @class
@class HWeatherManager;
@protocol HWeatherManagerDelegate <NSObject>
//use the delegate pass by value
-(void)test:(NSString *)str;
@end
@interface HWeatherManager : NSObject
@property (nonatomic,strong)UIViewController <HWeatherManagerDelegate> * delegate;
+(HWeatherManager *)defaultManager;
-(void)start;
-(void)endWeather;
@end
实现部分
#import "HWeatherManager.h"
#import "HWeatherViewController.h"
@implementation HWeatherManager
+(HWeatherManager *)defaultManager
{
static HWeatherManager *manager=Nil;
@synchronized(self)
{
if (manager==Nil) {
manager=[[HWeatherManager alloc]init];
[HWeatherViewController class];
}
}
return manager;
}
-(void)start
{
// [self.delegate test:@"hello"];
NSBundle *bundle=[NSBundle bundleWithURL:[[NSBundle mainBundle]URLForResource:@"HWeatherDataLibResources" withExtension:@"bundle"]];
UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"WeatherStoryboard" bundle:bundle];
// NSLog(@"--%@",navigation);
[self.delegate presentViewController:[storyboard instantiateInitialViewController] animated:YES completion:^{
}];
}
-(void)endWeather
{
UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:Nil];
[self.delegate presentViewController:[storyboard instantiateViewControllerWithIdentifier:@"endWeather"] animated:YES completion:^{
}];
}
@end
最新文章
- iOS ---Swift学习与复习
- oracle操作之传输表空间
- Chrome插件开发
- 设置session的生存时间
- C语言之宏
- Winform之跨线程访问控件(在进度条上显示字体)
- 定时执行Timer
- ASP.NET MVC全局观
- U盘启动时无USB-HDD选项的解决方案
- boost asio allocation
- Mongo C# Driver 聚合使用---深入浅出
- CSS3 Flex布局
- Android EditText常用属性
- java.lang.ClassCastException: cn.itcase.serviceImpl.servicestudentImpl cannot be cast to javax.servlet.Servlet
- 关于web.xml中配置Spring字符编码过滤器以解决中文乱码的问题
- warning: LF will be replaced by CRLF in ***. The file will have its original line endings in your working directory.
- Linux机器工作环境安装
- String和StringBuffer的机制差别
- spark on yarn,client模式时,执行spark-submit命令后命令行日志和YARN AM日志
- python--函数程序分析