1

I am trying to integrate AdWhirl into my iPhone app using an AppDelegate singleton so I can use the same AdWhirl instance across multiple views, but cannot figure out how to resize the tables in those views. The code I am using is:

in ...AppDelegate.h:

#import "AdWhirlView.h"
#import "AdWhirlDelegateProtocol.h"

@interface ...AppDelegate : NSObject <UIApplicationDelegate, AdWhirlDelegate>
AdWhirlView *awView;

...

@property (nonatomic, retain) AdWhirlView *awView;

in ...AppDelegate.m didFinishLaunchingWithOptions:

awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];

also in ...AppDelegate.m I add the required delegate methods

(NSString *)adWhirlApplicationKey...
(UIViewController *)viewControllerForPresentingModalView...

This code allows me to display the same Ad across multiple views but I cannot figure out how to resize a UITableView to change its height to be shorter if an Ad is displaying, so that the UITableView either displays full height if there is no Ad, or is resized if there is an Ad at the bottom of the screen. I have the UITableView as a subview of a UIViewController called myMainView.

I tried changing the autosize properties in the Nib file for the UITableView to have a variable spacer at the bottom, and am adding the AdWhirl instance into the view with this code:

...AppDelegate * myDelegate = (...AppDelegate *)[[UIApplication sharedApplication] delegate];
[myDelegate.awView setFrame:CGRectMake(0, 480-20-44-50, 320, 50)];
[self.myMainView addSubview: myDelegate.awView];

This displays the Ad at the correct location at the bottom of the screen but the UITableView is not resizing. How should I be doing this?

competent_tech
  • 44,465
  • 11
  • 90
  • 113
user955853
  • 399
  • 2
  • 14

1 Answers1

0

I think you have to create a UIView with an embedded UITableView. I've tried to do something similar and this was the only way I could get it to work. A top-level UITableView is auto-resized to take up the entire screen.

Just expanding on that, you probably want to declare something in your header like so:

@interface ExampleClass:UIViewController {
    UITableView *tableView;
}

@property (nonatomic,retain) IBOutlet UITableView *tableView;

Then in your actual implementation, you can resize that declared tablview whenever you need to by doing:

CGRect tableFrame = tableView.frame;
//Decrease the height of table by height of ad banner
tableFrame.size.height = tableView.frame.size.height - adBannerView.frame.size.height;

tableView.frame = tableFrame;
RajPara
  • 2,281
  • 1
  • 16
  • 9
Norman
  • 453
  • 3
  • 5
  • Ok, so I have the UITableView as a subView of a UIView, and I see that I need to manually resize these tableView when I have an Ad. But how do I know when AdWhirl is displaying an ad so that I can resize the tableView? – user955853 Nov 08 '11 at 05:37
  • 1
    I figured out how to do this. Basically, in ViewWillAppear, I added the line myDelegate.awView.delegate = self; This lets me listen for the appropriate delegate events that AdWhirl sends. The relevant ones being adWhirlDidReceiveAd, and adWhirlDidFailToReceiveAd. There is also a BOOL adExists that can be used when the view first appears to determine if an Ad is already displaying. I can then animate the Ad in or out as described above. – user955853 Nov 09 '11 at 22:53
  • Great, I've never use AdWhirl. – Norman Nov 11 '11 at 03:19