将Admob广告添加到UITableView [英] Adding Admob ads to UITableView
问题描述
这是原始代码。我是iOS开发的初学者,如何修改代码,以便将Admob广告加载到表格视图的底部?我尝试按照 http://jmsliu.com/上的指南进行操作。 1207 / add-google-admob-in-ios-apps.html ,但无法使其正常工作。
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];
}];
}
推荐答案
您共享的教程使用 UITableView
的标题 header
来显示广告。也许这不是一个好主意,因为您可能需要出于自己的目的使用这些标头。
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.
我知道您想将广告放在屏幕底部。在这种情况下,最好在 UITableView
下使用 UIView
。在这种情况下,您需要将 UITableViewController
更改为 UIViewController
才能做到这一点。
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.
如果要在 UITableView
的底部添加添加,则应将其视为单元格N + 1(为N,其大小为 self.prefixArray
),并更新表回调以正确处理特殊情况。
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.
这篇关于将Admob广告添加到UITableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!