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、當(dāng)內(nèi)存過低時,需要釋放一些不需要使用的視圖時,即將釋放時調(diào)用(已過期)
- (void)viewWillUnload {
    [super viewWillUnload];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 9、當(dāng)內(nèi)存過低,釋放一些不需要的視圖時調(diào)用(已過期)
- (void)viewDidUnload {
    [super viewDidUnload];
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

// 控制器銷毀時調(diào)用
- (void)dealloc {
    NSLog(@"%s, line = %d", __FUNCTION__, __LINE__);
}

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

// 2、表盤加載的時候調(diào)用(類似awakeFromNib)
- (void)awakeWithContext:(id)context {
    [super awakeWithContext:context];

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

// 3、視圖即將展示的時候調(diào)用(類似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、跳頁的時候調(diào)用(類似viewDidDisAppear)
- (void)didDeactivate {
    // This method is called when watch view controller is no longer visible
    [super didDeactivate];
    NSLog(@"%s, line= %d", __FUNCTION__, __LINE__);
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容