Integrating Inline Ads in UITableView - adform/adform-ios-sdk GitHub Wiki

Adding ads to UITableView

Inline ads can be added to a UITableView or any other collection view container. It can be added as a UITableView section headers and footers or cells. When adding ad view to table view you should ensure that you are properly reusing views to avoid performance issues. The example code provided below shows you how to add inline ads to table view as section footers.

Swift

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return AFAdInline.defaultAdSize().height
}

override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    if let footer = tableView.dequeueReusableHeaderFooterView(withIdentifier: "AdFooterIdentifier") {
        return footer
    }
    
    let footer = UITableViewHeaderFooterView(reuseIdentifier: "AdFooterIdentifier")
    
    let adView = AFAdInline(adTag: masterTag, presenting: self)
    footer.addSubview(adView)
    adView.loadAd()
    
    return footer
}
Objective-C
- (CGFloat )tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    //Returns default ad view size 320x50 for iPhone and 728x90 for iPad, you should use some kind of constant defining the size of your ad placement.
    return [AFAdInline defaultAdSize].height;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section { 
   UITableViewHeaderFooterView *footerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"AdFooterIdentifier"];
    
    if (!footerView) {
	footerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"AdViewFooterIdentifier"];
            
	AFAdInline *adView = [[AFAdInline alloc] initWithMasterTagId:mtag presentingViewController:self];
        [footerView.contentView addSubview:adView];
        [adView loadAd];
   }     
    
   return footerView;
}

Sample code:

For a complete example of how to add Adform inline ads to UITableView, check out the sample app.

⚠️ **GitHub.com Fallback** ⚠️