我正在尋找在我的應用程序中添加AdMob橫幅。我已經將它們放置在每個屏幕的底部,並且它可以正常工作,但並不完全是UIViewControllers。如何將靜態廣告橫幅添加到UITableViewController中?
當我把一個添加到UITableViewController它開始在屏幕底部的正確位置,但是當我滾動表時,它隨着它移動。當我滾動表格時,我需要將廣告靜態停留在屏幕的底部。
這裏是我的代碼:
- (void)displayGAD
{
// The frame of the banner is initialized off screen.
// If an ad loads then it will animate onto the screen.
self.bannerView = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,
self.view.frame.size.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
self.bannerView.adUnitID = self.adUnitID;
self.bannerView.delegate = self;
self.bannerView.rootViewController = self;
[self.view addSubview:self.bannerView];
[self.bannerView loadRequest:[self createRequest]];
}
- (GADRequest *)createRequest
{
GADRequest *request = [GADRequest request];
#warning Comment this out before distribution
request.testDevices = [NSArray arrayWithObjects:@"84ea3d9789cabb0a34176cbb52c0f992", @"abf08fe141b95987d27ac068602605b8", GAD_SIMULATOR_ID, nil];
return request;
}
- (void)adViewDidReceiveAd:(GADBannerView *)view
{
NSLog(@"Received Ad");
[UIView animateWithDuration:1.0 animations:^ {
view.frame = CGRectMake(0.0,
self.view.frame.size.height - view.frame.size.height,
view.frame.size.width,
view.frame.size.height);
}];
}
- (void)adView:(GADBannerView *)view didFailToReceiveAdWithError:(GADRequestError *)error
{
NSLog(@"Failed to receive ad with error: %@", [error localizedFailureReason]);
}
我已經看到了多個例子是,我怎麼可以嵌入廣告插入到表視圖,但沒有什麼具體的我要怎麼做。我唯一讀到的就是我應該將表視圖放入一個容器視圖中,然後將該廣告添加到該視圖中。我不知道我會怎麼做,但是,因爲這是一個UITableViewController。
你可以把這個代碼。我也需要它,但我是iOS編程的新手,很難從描述中去追蹤。 – WebOrCode