# 題目1 View Life Cycle. When does IBOutlet connect? ## Q1 為什麼iOS需要Life Cycle? ### 1. 從Application Life Cycle說起 每个应用程序都有其自身的生命周期(Life Cycle),它定义了应用程序从启动到终止的整个过程 Life Cycle 分類 ![](https://hackmd.io/_uploads/rkN2tqhBh.png =25%x) 點開應用程式 | Column 1 | Column 2 | Column 3 | | -------- | -------- | -------- | | ![](https://hackmd.io/_uploads/HJ4D_c2r3.png)| ![](https://hackmd.io/_uploads/SkVK_qnrn.png)| ![](https://hackmd.io/_uploads/ByGq_q3Sn.png)| 切換到另外一個應用程式 | Column 1 | Column 2 | Column 3 | | -------- | -------- | -------- | | ![](https://hackmd.io/_uploads/HyEadq2rn.png)| ![](https://hackmd.io/_uploads/ry4ROqnrn.png)| ![](https://hackmd.io/_uploads/HyxlK52Hh.png)| 當需要更多記憶體時 | Column 1 | Column 2 | Column 3 | | -------- | -------- | -------- | | ![](https://hackmd.io/_uploads/Hy9vK9nHh.png =50%x)| Text | Text | ## Q2 View裡的Life Cycle 大比較 ### 1. UIView 的 Life Cycle ### 2. UIViewController 的 Life Cycle 誰會先執行 viewDidLoad vs viewWillAppear ![](https://hackmd.io/_uploads/H1zjjq2H3.png) >viewDidLoad 剛ㄌㄡ (UIViewController first load into the memory,在顯示螢幕之前) >>viewWillAppear 顯示畫面前 (is about to presented on screen ,但在顯示之前) #### View與ViewController 畫面改變會用到的method * 原則 先Will後Did * loadView (完成一些關鍵View的初始化工作,比如UINavigationViewController和UITabBarController等容器類) | 在rootView之後,在ViewController與螢幕上的Viewer之前 | 接在viewWillApear之後,View與ViewController之後 | | | -------- | -------- | -------- | | ![](https://hackmd.io/_uploads/rJarCq2Bh.png)|![](https://hackmd.io/_uploads/B128R93B2.png) | | - init - loadView -- viewDidLoad (他override loadView) -- viewWillAppear 畫面將顯示 前 執行 -- viewDidAppear 畫面顯示 後 執行 -- viewWillDisappear 畫面將消失 前 執行 -- viewDidDisappear 畫面已消消 後 執行 - deinit ### 3. 程式碼範例 #### 1. debug print #### 2. 頁面切回,viewwillappear有 viewdidload沒有 ## Q3 面試喜歡問 ### 1. what order the methods are called (viewdidLoad、viewWillAppear) UIView ### 2. what order the methods are called (viewdidLoad、viewWillAppear) UIView Controller ### 3. identify the order in which the lifecycle methods for both View A and View B are called | Column 1 | Column 2 | | | -------- | -------- | -------- | | ![](https://hackmd.io/_uploads/HkjeS9hB3.png)| ![](https://hackmd.io/_uploads/HyP-r9hS3.png)| | Column 1 | Column 2 | | | -------- | -------- | -------- | | ![](https://hackmd.io/_uploads/S11Grq2Sn.png)| ![](https://hackmd.io/_uploads/SJ-7rchB2.png)| | [Job Interview - View Lifecycle](https://www.youtube.com/watch?v=1kiNLRfu0Do&ab_channel=Udacity) # 讀書會每組 ## MVC v.s. MVVM Orton ### 1. V+C <-> M 解決方法 MVVM 4. ## Delegate ## h2 ###### tags: `[讀書會]`