[英]Add admob view to the top or bottom of a UITableView programmatically?
I hope to add a admob view at the top or bottom of an UITableView
. 我希望在UITableView
的顶部或底部添加一个admob视图。 In Interface Builder it is easy -- just drag the view to the top or bottom of the UITableView
. 在Interface Builder中,它很简单 - 只需将视图拖动到UITableView
的顶部或底部即可。 But I would like to add view to the top or bottom of the table dynamically using code. 但我想使用代码动态地将视图添加到表的顶部或底部。
You can add header or footer views to a UITableView
by implementing the following UITableViewDelegate
methods in your UITableViewController
: 您可以添加页眉或页脚视图一个UITableView
通过实施以下UITableViewDelegate
在你的方法UITableViewController
:
- (CGFloat)tableView:(UITableView *)tableView
heightForHeaderInSection:(NSInteger)section
{
CGFloat height = 100.0; // this should be the height of your admob view
return height;
}
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = myAdMobView; // init your view or reference your admob view
return headerView;
}
For more informtation, see the documentation on the UITableViewDelegate protocol . 有关更多信息,请参阅UITableViewDelegate协议的文档 。
设置表的headerView和footerView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.