zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    (转)hdu 3436Queue-jumpers--splay+离散化
    (原)2018牛课多校第4场--G
    解压和生成 system.img&data.img ( ext4格式)
    Linux中的shift命令
    git commit 编辑器
    关于android.mk中的LOCAL_OVERRIDES_PACKAGES 说明
    android源码解析 ---- camera 照相机 摄像机
    补丁git format-patch && git-am用法
    LCD背光设备的 驱动框架2
    PWM(脉宽调制)的基本原理 及其 应用实例
  • 原文地址:https://www.cnblogs.com/huntaiji/p/3501690.html
Copyright © 2011-2022 走看看