1.VC生命周期
A页面显示
loadView -> viewDidLoad->viewWillAppear->viewDidAppear
A页面跳转B页面
A loadView ->A viewDidLoad->B viewWillDisappear->A viewWillAppear->B viewDidDisappear->A viewDidAppear
B页面返回A页面
B viewWillDisappear->A viewWillAppear->B viewDidDisappear->A viewDidAppear->B dealloc
2.创建单例 创建.h文件,定义宏
ifndef XLXSingleton_h
define XLXSingleton_h
// @interface
define singleton_interface(className) \
- (instancetype)shared##className;
// @implementation
define singleton_implementation(className) \
static className *_instance; \
- (instancetype)shared##className
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [[self alloc] init];
});
return _instance;
} \ - (instancetype)allocWithZone:(NSZone *)zone
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_instance = [super allocWithZone:zone];
});
return _instance;
} \
- (instancetype)copyWithZone:(NSZone *)zone{
return _instance;
} \ - (instancetype)mutableCopyWithZone:(NSZone *)zone{
return _instance;
}