views:

362

answers:

3

I started by creating a universal window based app. Starting with the iPhone version I created a UIViewController and associated nib.

My App delegate:

rootViewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[window makeKeyAndVisible];
[window addSubview:rootViewController.view];
return YES;

My RootViewController:

- (void)viewDidLoad {
[super viewDidLoad];
adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero()];
[self.view addSubview:adBannerView];

}

I've tried instanciating buttons instead of the adBanner and I get the same result.

My RootViewController's nib has not been changed since x-code created it for me. My MainWindow_iPhone.xib also is stock.

What's causing this?

Update

After changing the app's orientation the adBannerView (or button...) will snap into the correct place at y=0. I've tried setting adBannerView's y location to 20 presumably to compensate for the status bar and that makes everything display correctly until I change orientation. Then everything moves down 20 pixels and will leave a 20 pixel space between the adBannerView and the status bar.

A: 

CGRectZero is literally a zero rect (0, 0, 0, 0), so ADBannerView should never show up if it really has a width and height of 0. You probably want to try initWithFrame:self.view.frame or so…

Evadne Wu
Yeah, but from the docs the ADBannerView should be initiated with CGRectZero if its going up top. When I tried using UIButton instead I set a valid frame at 0,0,100,50 and still have the same issue. It also is identical if I set the ADBannerView or UIButton up in IB instead of in code.
jamone
A: 

You should set the size identifier before adding the view:

- (void)viewDidLoad {
[super viewDidLoad];
adBannerView = [[ADBannerView alloc] initWithFrame:CGRectZero()];

if(UIInterfaceOrientationIsPortrait([[UIDevice currentDevice] orientation]))
    adBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
else
    adBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier480x32;


[self.view addSubview:adBannerView];

// now you can treat it like any other subview
// For example, if you want to move it to the bottom of the view, do this:

CGRect frame = adBannerView.frame;
frame.origin.y = self.view.frame.size.height - frame.size.height;
[adBannerView setFrame:frame];

}

Whenever the interface rotates, you should notify the banner to change its size.

Assuming you have access to WWDC videos (which is available for free), check video session 305. It demos adding the banner.

Mo
I tried this and still no change. Since the issue occurs even if I try placing a UIButton or any other control at y=0, so I don't see how its iAd related.
jamone
+1  A: 

Try to add the next line in your viewDidLoad (right after [super viewDidLoad];):

self.view.frame = [[UIScreen mainScreen] applicationFrame];
Michael Kessler
Well that fixed it. I don't see why it was needed because using NSLog I see that self.view.frame's values are identical before and after this line. Oh well... Thanks.
jamone
You welcome. :) I've spent few hours on this when I faced it for the first time...
Michael Kessler