ios - 以编程方式将 admob View 添加到 UITableView 的顶部或底部?

标签 ios cocoa-touch uitableview

enter image description here

我希望在 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/

相关文章:

ios - 本地开发如何下载Podspec依赖

iphone - 计时器:时间到时在另一个 View Controller 上看到警报

ios - 如何以编程方式在 View 之间转换?

iphone - 如何让 UITableViewCell 的 subview 扩展到单元格的边界之外

ios - 升级到 MT 4.0 后索引 TableViews 不显示

ios - swift |为什么我的 UITableView 是空的(自定义单元格)

iOS模拟器屏幕尺寸

ios - 如何在 MGL mapView 中缩放,以便 View 包含 map 上的一个 "object"

ios - 如何让 Google map 标记标题在 iOS 中闪烁?

cocoa-touch - UIManagedDocument 是否处理冲突