我希望在 UITableView
的顶部或底部添加一个 admob View .
在 Interface Builder 中很简单——只需将 View 拖到 UITableView
的顶部或底部.
但我想使用代码动态地将 View 添加到表格的顶部或底部。
最佳答案
您可以将页眉或页脚 View 添加到 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;
}
有关详细信息,请参阅 documentation on the UITableViewDelegate protocol .
关于ios - 以编程方式将 admob View 添加到 UITableView 的顶部或底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15323515/