重写viewWillAppear 和 viewWillDisAppear时[super viewWillAppear] 和 [super viewWillDisappear]的调用位置

参考网址: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 }

 

如有错误 敬请指正

如需转载 请注明出处 谢谢

 

posted on 2017-09-04 17:02  ITCoderW  阅读(1523)  评论(0编辑  收藏  举报

导航