zoukankan      html  css  js  c++  java
  • 懒加载的使用

    //
    //  LazyViewController.m
    //  Share
    //
    //  Created by lanouhn on 15/1/20.
    //  Copyright (c) 2015年 niutiantian. All rights reserved.
    //

    #import "LazyViewController.h"

    @interface LazyViewController ()

    @end

    @implementation LazyViewController

    - (void)dealloc
    {
        self.myLabel = nil;
        [super dealloc];
    }


    //1.懒加载基本

    //懒加载——也称为延迟加载,即在需要的时候才加载(效率低,占用内存小)。所谓懒加载,写的是其get方法.

    //注意:如果是懒加载的话则一定要注意先判断是否已经有了,如果没有那么再去进行实例化
    //
    //2.使用懒加载的好处:

    //(1)不必将创建对象的代码全部写在viewDidLoad方法中,代码的可读性更强

    //(2)每个控件的getter方法中分别负责各自的实例化处理,代码彼此之间的独立性强,松耦合

    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        self.myLabel.text = @"1111111";
    }
        //label延迟加载
        //判断是否已经有了lable 没有则实例化
    -(UILabel *)myLabel{
        if (!_myLabel) {
            self.myLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 50, 50)];
            [self.view addSubview:_myLabel];
            [_myLabel release];
        }
        return _myLabel;
    }

    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }

    /*
    #pragma mark - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
        // Get the new view controller using [segue destinationViewController].
        // Pass the selected object to the new view controller.
    }
    */

    @end

     
  • 相关阅读:
    调用GOOGLE的TTS实现文字转语音(XE7+小米2)(XE10.1+小米5)
    Android实例-设置消息提醒(XE8+小米2)
    FastReport二维码打印存在的问题
    一个DELPHI操作USB摄像头类
    利用Delphi编程控制摄像头(图)
    Delphi实现拍照控件的程序代码
    win dos命令行设置ip和dns
    daemontools管理fast-fail的zookeeper
    zookeeper定时清理log
    生成所有全排列 非递归和递归实现
  • 原文地址:https://www.cnblogs.com/tian-sun/p/4237735.html
Copyright © 2011-2022 走看看