在跨多个视图显示AdWhirl广告时调整UITableView大小 [英] Resizing UITableView When Displaying AdWhirl Ads Across Multiple Views

查看:227
本文介绍了在跨多个视图显示AdWhirl广告时调整UITableView大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用AppDelegate单例集合将AdWhirl集成到我的iPhone应用程序中,因此我可以在多个视图中使用相同的AdWhirl实例,但无法确定如何调整这些视图中的表格大小。我使用的代码是:



in ... AppDelegate.h:

  #importAdWhirlView.h
#importAdWhirlDelegateProtocol.h

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

...

@property(nonatomic,retain)AdWhirlView * awView;

在... AppDelegate.m didFinishLaunchingWithOptions:

  awView = [AdWhirlView requestAdWhirlViewWithDelegate:self]; 

也在... AppDelegate.m中添加所需的委托方法

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

这段代码允许我在多个视图中显示相同的广告,但是我不知道如何调整UITableView的大小,以便在广告显示时将其缩短,以便UITableView如果没有广告,则显示完整高度;如果屏幕底部有广告,则调整大小。我有UITableView作为UIViewController的一个子视图名为myMainView。



我试图更改UIBableView的NIB文件中的autosize属性在底部有一个可变的spacer,并且使用此代码将AdWhirl实例添加到视图中:

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

这会在屏幕底部的正确位置显示广告,但UITableView未调整大小。我应该怎么做?

解决方案

我想你必须创建一个嵌入式UITableView的UIView。我试图做类似的事情,这是我可以让它工作的唯一方式。顶层的UITableView是自动调整大小以占据整个屏幕。



只是扩展,你可能想在标题中声明如下:

  @interface ExampleClass:UIViewController {
UITableView * tableView;
}

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

然后在你的实际实现中,你可以在需要的时候调整声明的tablview的大小:

  CGRect tableFrame = tableView.frame; 
//根据广告横幅的高度降低表的高度
tableFrame.size.height = tableView.frame.size.height - adBannerView.frame.size.height;

tableView.frame = tableFrame;


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?

解决方案

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;

这篇关于在跨多个视图显示AdWhirl广告时调整UITableView大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆