When you begin to duplicate code, you're increasing the efforts required to maintain your app, because you have to go through every instance and change it. In our last exercise, we have three similar blocks of code that we can combine into one method that intelligently handles the situations. This function will handle the hiding and displaying of our ad, depending on the banner's availability. Continuing with our demo app, complete the following steps to clean up the code:
1. Before the delegate methods of the banner, and before the
pragma mark
, create an empty method by adding this code:-(void) adjustBannerVisibility { }
2. We'll need to add the following to the header file,
iAd_Demo_AppViewController.h
, before the@end
statementin the file add to tell the project that this new method is available:-(void) adjustBannerVisibility;
3. This will suppress any warnings from Xcode about unknown methods. Now return back to the main file—
iAd_Demo_AppViewController...