Putting ADBannerView on top of the UINavigationController

I am trying to place an iAd banner in an application based on UINavigationController (this is not the standard navigation application offered by xcode because I don't need a table view). I would like to place ADBanner at the bottom to be always visible, regardless of how the user pops up and pushes the views.

I studied the iAdSuite example in the Apple code example, but although it reported “best practices”, I don’t think this is the best practice for what I need. It basically declares ADBannerView in the application delegate class, and then implements the ADBannerViewDelegate methods for each individual view that applications need. This means that the ADBannerViewDelegate methods are repeated over and over for each class controller class you need! That doesn't seem too smart ... :(

I would prefer the approach to be more similar to what Apple itself does in the application based on the tab bar, where you have the part of the window that is always occupied by the tab controller, and all the views above without affecting the tab below. You cannot directly put ADBannerView together with the nav controller in the application delegate, because ADBanner needs to be placed in the view controller (otherwise you will get a runtime error).

I tried a subclass from UIViewController, implementing ADBannerViewDelegate in this class, and put it in rootViewController along with UINavigationController, but I had no luck with this approach ...

Has anyone found a good, easy way? Any hint?

Thanks for any help ...

+4
source share
1 answer

You can have only one class for ADBannerViewDelegate and only one instance of ADBanner . When the current active change changes, remove ADBanner from the old view, add it as a subview to the new view.

EDIT:

to clarify, you do not need each view to implement ADBannerViewDelegate . You should have only one class that implements it (this class does not have to be a view controller, for that matter).

You will also need to save somewhere a property that points to the current active view (for example, you can update this property in your navigation controller navigationController:didShowViewController:animated: or create your own protocol for this if your views appear in a more complex way )

Then in your ADBannerViewDelegate you simply resize the view currently specified by this property of the current view. The actual view does not even need to know that it has an ad;)

+2
source

Source: https://habr.com/ru/post/1347628/


All Articles