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

  • 相关阅读:
    mysql中的enum型
    mysql中的时间year/date/time/datetime
    一些数字的属性
    mysql增删
    Perl6 Bailador框架(8):自定义400/500
    react: typescript jest && enzyme
    webstorm tslint配置
    react: typescript import images alias
    JSONP原理及简单实现
    纯css画三角形
  • 原文地址:https://www.cnblogs.com/huntaiji/p/3501690.html
Copyright © 2011-2022 走看看