Lazy-Loading use

Source: Internet
Author: User

Created by Lanouhn on 15/1/20.
Copyright (c) 2015 Niutiantian. All rights reserved.

#import "LazyViewController.h"

@interface Lazyviewcontroller ()


@implementation Lazyviewcontroller

-(void) dealloc
Self.mylabel = nil;
[Super Dealloc];

1. Lazy Loading Basic

Lazy Loading--also known as deferred loading--is loaded when needed (low efficiency, small memory footprint). The so-called lazy load, write is its get method.

Note: If it is lazy loading, it is important to be aware of whether there is already, if not then to instantiate
2. Benefits of using lazy loading:

(1) You do not have to write all the code of the created object in the Viewdidload method, the code is more readable

(2) Each control's getter method is responsible for the respective instantiation processing, the code is independent of each other, loosely coupled

-(void) Viewdidload {
[Super Viewdidload];
Do any additional setup after loading the view.
Self.myLabel.text = @ "1111111";
Label Lazy Loading
Determine if a lable is already in existence and not instantiated
-(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 the can be recreated.

#pragma mark-navigation

In a storyboard-based application, you'll 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.


Lazy-Loading use

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.