Resizing UITableView When Displaying AdWhirl Ads Across Multiple Views

北城以北 提交于 2019-12-24 06:39:00

问题


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?


回答1:


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;


来源:https://stackoverflow.com/questions/8032325/resizing-uitableview-when-displaying-adwhirl-ads-across-multiple-views

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!