私はGoogle AdMob Ads iOSのチュートリアルに従っています。 すべて私はUITableViewに広告を追加しようとするまでうまく動作します。 私のデザインは、最初のセクションに広告が表示される2つのセクションと、2番目のセクションの表データを持つというものでした。しかし、これはあまりうまくいきませんが、最初のセクションで広告が表示されますが、10番目のセルごとに繰り返されます。私は一度だけ広告をしたい。どのように私はこれを行うのですか?ここでUITableView GADBannerView
は私のコードです...
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem *refreshButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refresh:)];
self.navigationItem.rightBarButtonItem = refreshButtonItem;
[refreshButtonItem release];
// Create a view of the standard size at the bottom of the screen.
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(0.0,
0.0,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = @"blablabla";
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self;
GADRequest *adMobRequest = [GADRequest request];
adMobRequest.testDevices = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID, // Simulator
@"fafasfasdfasdrasdasfasfaasdsd", nil];
// Initiate a generic request to load it with an ad.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
if (section == 0) {
return 1;
} else {
return 50;
}
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"Cell"];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if (indexPath.section == 0) {
if (indexPath.row == 0) {
[cell addSubview:bannerView_];
}
} else {
cell.textLabel.text = @"Test";
cell.detailTextLabel.text = @"Test";
cell.imageView.image = nil;
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 50;
}
がcellForRowAtIndexPath:
でこの..
tableviewcellに追加する前に広告をリクエストしています。これは、ユーザーが画面に表示する前に広告を作成したためにインプレッションが送信されます。 –