iOS控制器生命周期和Apple Watch控制器生命周期

  • iOS控制器生命周期
// 1、初始化
- (instancetype)init {
    self = [super init];
    if (self) {
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
    }
    return self;
}

// 2、View加载
- (void)loadView {
    [super loadView];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 3、View加载完成
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 4、View即将显示
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 5、View显示完成
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 6、View即将消失
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 7、View消失完成
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 8、当内存过低时,需要释放一些不需要使用的视图时,即将释放时调用(已过期)
- (void)viewWillUnload {
    [super viewWillUnload];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 9、当内存过低,释放一些不需要的视图时调用(已过期)
- (void)viewDidUnload {
    [super viewDidUnload];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 控制器销毁时调用
- (void)dealloc {
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

  • Apple Watch生命周期
// 1、init

// 2、表盘加载的时候调用(类似awakeFromNib)
- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];

    // Configure interface objects here.
    NSLog(@"%s, line= %d", __FUNCTION__, __LINE__);
}

// 3、视图即将展示的时候调用(类似viewWillAppear)
- (void)willActivate {
    // This method is called when watch view controller is about to be visible to user
    [super willActivate];
    NSLog(@"%s, line= %d", __FUNCTION__, __LINE__);
}

// 3、跳页的时候调用(类似viewDidDisAppear)
- (void)didDeactivate {
    // This method is called when watch view controller is no longer visible
    [super didDeactivate];
    NSLog(@"%s, line= %d", __FUNCTION__, __LINE__);
}

你可能感兴趣的:(iOS控制器生命周期和Apple Watch控制器生命周期)