重寫viewWillAppear 和 viewWillDisAppear時[super viewWillAppear] 和 [super viewWillDisappear]的調用位置

來源:互聯網
上載者:User

標籤:target   href   blog   https   工具   nbsp   eww   方法   分析工具   

參考網址:https://stackoverflow.com/questions/3906704/when-should-i-call-super

在寫代碼的過程中如果重寫了viewWillAppear 和 viewWillDisAppear方法,但是沒有調用[super viewWillAppear] 和 [super viewWillDisappear]的話使用靜態分析工具(快速鍵 command + shift + B)分析的時候會出現問題

如展示出來出現問題的情況和 XCode給出的問題說明:

/ViewController.m:29:1: The ‘viewWillAppear:‘ instance method in UIViewController subclass ‘ViewController‘ is missing a [super viewWillAppear:] call

/ViewController.m:29:1: The ‘viewWillAppear:‘ instance method in UIViewController subclass ‘ViewController‘ is missing a [super viewWillAppear:] call

 

如果調用了super 的方法的話在使用靜態分析工具的時候就不會出現問題

那麼說我們如果是在這兩個方法裡邊要執行其他的代碼的話,應該是要先調用super 還是要先調用我們要執行的別的代碼呢?

https://stackoverflow.com/questions/3906704/when-should-i-call-super

stackoverflow上邊是這麼說的 如所示

 

 以後可以這麼寫

 1 - (void)viewWillAppear:(BOOL)animated{ 2     [super viewWillAppear:animated]; 3     //在這裡調用要執行的代碼 4      5      6 } 7  8 - (void)viewDidAppear:(BOOL)animated{ 9     //在這裡調用要執行的代碼10     [super viewDidAppear:animated];11 }

 

如有錯誤 敬請指正

如需轉載 請註明出處 謝謝

 

重寫viewWillAppear 和 viewWillDisAppear時[super viewWillAppear] 和 [super viewWillDisappear]的調用位置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.