iOS懒加载
来源:互联网 发布:在淘宝买摩托车可靠吗 编辑:程序博客网 时间:2024/04/30 06:22
懒加载,英文名LazyLoad。也称为延迟加载,即在需要的时候才加载(效率低,占用内存小)。所谓懒加载,写的是其get方法。
- 不必将创建对象的代码全部写在viewDidLoad方法中,代码的可读性更强。
- 每个控件的getter方法中分别负责各自的实例化处理,代码彼此之间的独立性强,松耦合。
- 一定要先判断是否存在。
下面是示例代码
@interface ViewController () <CLLocationManagerDelegate>
@property (nonatomic,strong) CLLocationManager *locMgr;
@end
- (void)viewDidLoad {
[super viewDidLoad];
// 开始定位
[self.locMgr startUpdatingLocation];
}
- (CLLocationManager *)locMgr{
if (!_locMgr) { //判断是否为空
self.locMgr = [[CLLocationManager alloc] init];
// 设置代理
self.locMgr.delegate = self;
[self.locMgr requestAlwaysAuthorization];
}
return _locMgr;
}
@property (nonatomic,strong) CLLocationManager *locMgr;
@end
- (void)viewDidLoad {
[super viewDidLoad];
// 开始定位
[self.locMgr startUpdatingLocation];
}
- (CLLocationManager *)locMgr{
if (!_locMgr) { //判断是否为空
self.locMgr = [[CLLocationManager alloc] init];
// 设置代理
self.locMgr.delegate = self;
[self.locMgr requestAlwaysAuthorization];
}
return _locMgr;
}
0 0
- ios懒加载
- iOS 懒加载
- iOS懒加载
- IOS-懒加载
- ios 懒加载
- iOS 初始化 懒加载
- iOS懒加载问题
- iOS懒加载
- iOS懒加载
- IOS懒加载介绍
- iOS 懒加载模式
- iOS 懒加载
- iOS开发 -- 懒加载
- iOS懒加载
- iOS UI 懒加载
- iOS 开发懒加载
- iOS懒加载
- iOS懒加载
- C#中的扩展方法
- OOA/OOD/OOP
- 开通400电话需要提交的资料
- 算法导论22(基本的图算法)
- Oracle DDL,DML,DCL,TCL 基础概念
- iOS懒加载
- Android Intent的几种用法
- 文件编码格式
- Android App框架设计之编写基类BaseActivity
- 无约束最优化方法——牛顿法、拟牛顿法、BFGS、LBFGS
- Android中 记住密码(SharedPreferences)
- 设计模式-Factory
- SpringMVC-14 自定义拦截器
- 【 D3.js 高级系列 — 6.0 】 值域和颜色