2

I have a project built off the classic Master Detail template provided out of the box by Xcode. I am trying to incorporate the iAdSuite BannerViewController with out much success.

I have added BannerViewController.m & .h to my project, but I'm struggling to get my app to invoke the viewDidLoad in BannerViewController. I've been through the TabbedBanner sample pretty extensively and still don't see where BannerViewController is "tied" in.

Tried adding BannerViewController as a child view controller

BannerViewController *vbc = [[BannerViewController alloc] init];
[navigationController addChildViewController:vbc];

This code produces a tragic ending.

Any insight into this sample code or hints where to find additional info on using a shared banner would be appreciated.

Gogo
  • 267
  • 1
  • 2
  • 12
  • "This code produces a tragic ending." Hahaha, what!? What do you want to achieve exactly and what is your code actually doing? – luk2302 May 02 '15 at 16:39
  • It produces an uncaught exception in addBannerViewController. The main goal is to use a single instance of a iAd Banner across the application to reduce the fetch time for an ad and maximize revenue (according the the iAd docs). – Sean Murphy May 02 '15 at 16:44
  • .... what exception .... ? – luk2302 May 02 '15 at 16:44
  • *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array' – Sean Murphy May 02 '15 at 16:47
  • And what does that tell us? you try to access an element in empty array! where do you do it, xcode should tell you a method and line and show a stack trace where the error occured? – luk2302 May 02 '15 at 16:48
  • Exactly, so I'm not sure I'm even on the right track. I'm getting the sense that i'm adding one kludge onto another. ` _contentController = children[0];` is likely the root cause. Although, interestingly the assert isn't triggered. I am getting a full stack trace, just didn't include it here. – Sean Murphy May 02 '15 at 16:56
  • And why are you accessing `children[0]`, where do you add something to that array? If you don´t then there is nothing it and therefore you can not access it. – luk2302 May 02 '15 at 17:00
  • Further research indicates that for iOS 7 and later, the BannerViewController method is not really necessary. It's replaced by the code self.canDisplayBannerAds = YES; [Apple Developer Forum](https://devforums.apple.com/message/922541#922541) – Sean Murphy May 02 '15 at 20:40
  • I'm unfamiliar with the **iAdSuite BannerViewController** you've mentioned in your question. Can you provide a link? If you'd like to add the banner programmatically here's an answer that shows you how to do just that: http://stackoverflow.com/a/28708377/2108547 . Another option is using `self.canDisplayBannerAds = YES`. Add this to your `viewDidLoad` and you're good to go. This method of implementing your `ADBannerView` won't allow for much control though. – Daniel Storm May 03 '15 at 12:42
  • There are two sets of sample code: [iAdSuite](https://developer.apple.com/library/ios/samplecode/iAdSuite/Introduction/Intro.html) and [iAdSuite_with_storyboards](https://developer.apple.com/library/ios/samplecode/iAdSuite_Storyboard/Introduction/Intro.html). – Sean Murphy May 08 '15 at 23:24

1 Answers1

0

In storyboard: add a new view controller, set its class to bannerViewController, & add a container view to that VC. A second VC will be added when you add the container view, delete it.

Delete the segue between the root Navigation Controller and the table view controller.

Add a 'root view controller segue' between the Navigation Controller and container, view and an 'embed segue' between the container view and table view.

You will need to tweak the frame adjustments code in bannerViewController->viewDidLayoutSubviews to take account of the navigation bar in the navigation controller. That will get you banner ads in your table view, I have yet to figure out how to get them to show in the detail view.

Good luck.

mikejl
  • 1
  • 2