Jet Jet - 1 year ago 163
iOS Question

Is it a MUST for viewWillAppear to have [super viewWillAppear] method as well

I placed my code for iAd/AdMob ads in...


Ads work perfectly fine the way I have them now on all iOS devices.
When I connected my iPhone to Xcode and clicked on
Product -->Analyze
a message states...

instance method in
subclass 'iPhoneSIX' is missing a
[super viewWillAppear:]

I just accidentally stumbled upon this
thing. Do I really need to add
[super viewWillAppear]
even though everything works perfectly fine on all devices as it currently is. Will Apple reject my app if I don't pay attention to the
issue navigator?

Also, what does ...

[super viewWillAppear:YES];

What does calling this do?

Answer Source

Apple doesn't gets that specific when deciding to Accept or Reject your app. It only follows the guidelines, which doesn't get that much into the weeds of your specific methods.

Calling [super viewWillAppear:YES] is a best practice, and I would recommend it. Always including super ensures that any code in the super classes get called before executing any additional code. So if you or someone else coded a super class that expected some code to be executed, you are guaranteed to still execute it, rather than just overwriting the whole method in the subclass.

Say you have a view controller of type MyViewController which is a subclass of UIViewController. Then say you have another view controller of type MyOtherViewController, which is a subclass of MyViewController. Say you're coding now some things in viewWillAppear in MyOtherViewController. If you call super first, it will call viewWillAppear in MyViewController before executing any code. If viewWillAppear in MyViewController calls super first, then it will call viewWillAppear in UIViewController before executing any code.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download