Luc*_*Luc 2 xcode objective-c storyboard ios iad
我没有设法让iAd在故事板中工作,在UITableViewController中.
这基本上是我到目前为止所做的:在故事板中,我在我的UITableViewController场景的底部拖了一个iAd横幅视图.(我无法在视图中设置横幅,因为故事板会阻止它.我只能将iAd对象拖到第一个响应器和UITableViewController的图标旁边.)
在UITAbleViewController的标题中,我有:
#import <UIKit/UIKit.h>
#import "ListViewController.h"
#import <iAd/iAd.h>
@interface ListViewController : UITableViewController <ADBannerViewDelegate>{
bool bannerIsVisible;
}
@property (strong, nonatomic) IBOutlet ADBannerView *iAd;
@end
Run Code Online (Sandbox Code Playgroud)
在UITableViewController的实现中,我有:
- (void)viewDidLoad
{
[super viewDidLoad];
iAd.delegate = self;
// iAd.frame = CGRectMake(0.0,200.0,iAd.frame.size.width,iAd.frame.size.height); // does not work
// self.tableView.tableFooterView = iAd; // Display the banner at the middle of the screen (depending upon the number item of the table)
// Do not know how to have the default banner to appear at the very bottom of the screen (behind the tab bar) when the view is loaded ?
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(@"didFailToReceiveAdWithError");
if (bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
banner.frame = CGRectMake(0.0,350.0,banner.frame.size.width,banner.frame.size.height);
[UIView commitAnimations];
bannerIsVisible = NO;
}
}
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(@"bannerViewDidLoadAd");
if (!bannerIsVisible)
{
[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
banner.frame = CGRectMake(0.0,317.0,banner.frame.size.width,banner.frame.size.height);
[UIView commitAnimations];
bannerIsVisible = YES;
}
}
Run Code Online (Sandbox Code Playgroud)
我们的想法是让横幅出现在屏幕的底部,并在标签栏上方显示横幅加载是成功的.
我遇到的问题:通过这种配置,我可以看到有时会调用方法"didFailToReceiveAdWithError",有时会调用"bannerViewDidLoadAd",但在每种情况下都不显示横幅.
Tas*_*een 10
我知道我的答案太迟了,但是对于那些可能会访问这个帖子的人来说.这可能有助于他们
在头文件中
#import <UIKit/UIKit.h>
#import "ListViewController.h"
#import <iAd/iAd.h>
@interface ListViewController : UITableViewController <ADBannerViewDelegate>
@property (nonatomic, strong) ADBannerView *bannerForTableFooter;
@property (nonatomic) BOOL bannershouldBeVisible;
@end
Run Code Online (Sandbox Code Playgroud)
在.m文件中
-(ADBannerView *)bannerForTableFooter
{
if (!_bannerForTableFooter) {
_bannerForTableFooter = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
_bannerForTableFooter.delegate = self;
}
return _bannerForTableFooter;
}
Run Code Online (Sandbox Code Playgroud)
在ViewDidLoad中
self.bannerForTableFooter.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
然后添加这些tableView数据源方法
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
if (self.bannershouldBeVisible) {
return self.bannerForTableFooter.frame.size.height;
}
else
{
return 0;
}
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
if (self.bannershouldBeVisible) {
return self.bannerForTableFooter;
}
else
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
}
#pragma mark - iAd
-(void)bannerViewDidLoadAd:(ADBannerView *)bannerShown
{
self.bannershouldBeVisible = YES;
[self.tableView reloadData];
}
-(void)bannerView:(ADBannerView *)bannerShown didFailToReceiveAdWithError:(NSError *)error
{
self.bannershouldBeVisible = NO;
[self.tableView reloadData];
}
Run Code Online (Sandbox Code Playgroud)
你的问题很常见.它不会因为故事板而发生,而是由于你正在使用的事实而发生UITableViewController.UITableViewControllers给你很多免费的,但他们确实需要一些东西.其中一个"事物"是他们要求他们的观点是一个UITableView.
你有几个选择.这里有几个首选的.
1)添加您的iAd作为tableFooterView.这需要一些额外的工作来保持在屏幕上,同时在我对这个问题的回答中滚动.
2)将您的UITableViewController子类转换为UIViewController子类.有趣的是,上面提到的问题的OP最终会做什么.从本质上讲,您可以在动画iAd时动画(现在是子视图)tableView的帧.然后它将按预期工作.我在本回答中概述了转换为文件UIViewController中子类的基本步骤.xib,其中大部分应该适用于您.
有更好的方法.从这里:https: //github.com/romaonthego/RETableViewManager/issues/50
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect frame = self.iAd.frame;
frame.origin.y = scrollView.contentOffset.y + scrollView.frame.size.height-_iAd.frame.size.height; // Move view to the bottom on scroll
self.iAd.frame = frame;
[scrollView bringSubviewToFront:self.iAd];
}
Run Code Online (Sandbox Code Playgroud)
更新.iAd从那以后,有更好的方式在底部显示横幅iOS7.
- (void)viewDidLoad
{
[super viewDidLoad];
self.canDisplayBannerAds = YES;
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7075 次 |
| 最近记录: |