• 静态类项目中的经验总结


    一,创建静态类库为了别人调用,于是最好的入口应该是单例,下面是比较好的一种写法

    #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];

  • 相关阅读:
    javascript中无法通过div.style.left获取值的问题
    《Javascript高级程序设计第3版》精华总结
    前端面试笔试题回顾
    HTML 代码复用实践 (静态页面公共部分提取复用)
    将本地文件上传到远程库(二)
    ife-task0003学习收获总结
    将本地项目上传到git总结
    Minimum Size Subarray Sum —— LeetCode
    Binary Tree Preorder Traversal —— LeetCode
    Insertion Sort List —— LeetCode
  • 原文地址:https://www.cnblogs.com/huntaiji/p/3492752.html
Copyright © 2020-2023  润新知