//
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. 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.
}
*/
@end
Lazy-Loading use