问题
This is the original code. I am a beginner in iOS development, how should I modify the code such that Admob ads will be loaded at the bottom of tableview? I tried to follow the tutorial from http://jmsliu.com/1207/add-google-admob-in-ios-apps.html , but can't get it to work.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.prefixArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
NSDictionary *d = self.prefixArray[indexPath.row];
cell.textLabel.text = d[kMDTitleKey];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSDictionary *d = self.prefixArray[indexPath.row];
NSInteger entryID = [d[kMDIdentifierKey] integerValue];
self.searchBar.text = d[kMDTitleKey];
[self.db fetchDefinitionsWithID:entryID callback:^(NSDictionary *response) {
NSString *HTML = [self.HTMLRenderer renderHTML:response];
[self.webView loadHTMLString:HTML baseURL:nil];
[self.searchDisplayController setActive:NO animated:YES];
}];
}
回答1:
The tutorial you share uses the UITableView
's title header
to show an ad. Probably that's not a good idea since you'll probably would need to use those headers for your own purposes.
I understand you want to put ads at the bottom of the screen. In that case it would be a good idea to use an UIView
below UITableView
. In that case you'll need to change your UITableViewController
for an UIViewController
to be able to do that.
If you want to add the add at the bottom of the UITableView
you should think of it as the cell N+1 (being N the size of self.prefixArray
) and update your table callbacks to handle the special case correctly.
回答2:
You should add the advert view as the footerview for the tableview. Implement
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
where you will create the advert view and return it as the footer view
dont put the advert view inside a cell, as it will be dequeued and its just the incorrect place for it.
来源:https://stackoverflow.com/questions/29563670/adding-admob-ads-to-uitableview