I have a problem with implementing AdMob in my UITableView. I have an array (newsItems) that contains news-feeds from different websites. The array is sorted by the date of the newsitem. I want to display the newsitems in a tableview, but in the free version of the app I want an advertisement from AdMob to show in every 10th tableviewcell.
I used the code from an other answer to add the ads to the tableview:
if (0 == (row % 10)) {
//cells with an add
static NSString *MyIdentifier;
NSInteger row = [indexPath row];
MyIdentifier = [NSString stringWithFormat:@"AdCell%d", row];
cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
[cell.contentView addSubview:[AdMobView requestAdWithDelegate:self]];
return cell;
} else {
// the code to create a standard cell (simplified)
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue = [newsItems objectAtIndex:indexPath.row];
cell.text = cellValue;
}
I know this is not correct. By using “[newsItems objectAtIndex:indexPath.row]” the table is populated by going through the array and adding the newsitem at the index to the matching row. This means that if an add should be added to row 10, the corresponding newsItem at row 10 of the array is not ignored and overwritten by the AdWhirl-ad.
In stead I want that newsitem to be added to the row beneath the ad. Is this possible?