头文件
以此作为模板,记录于此
#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