The SDK provides a universal way to display advertisements inside the cell of scrollable controls, such as UITableView and UICollectionView.
We need you to edit your item Layout, so it has a wrapper/holder for the Ads. This is because we can not edit your data for adding new items to the adapter, so we take the existing item views and add the ads to them. You can customize which items have ads when you create the configuration for the infinite scroll. |
class TableViewInfiniteScrollViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var tableView:UITableView! ... override func viewDidLoad() { super.viewDidLoad() tableView = UITableView(frame: self.view.bounds, style: .plain) // Register a cell class tableView.register(InfScrlViewCell.self, forCellReuseIdentifier: "cell") tableView.delegate = self tableView.dataSource = self tableView.estimatedRowHeight = 300 tableView.rowHeight = UITableView.automaticDimension self.view.addSubview(tableView) NSLayoutConstraint.activate([ tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor), tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor), tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor) ]) ... } ... } |
class InfScrlViewCell: UITableViewCell { let centeredLabel = UILabel() // This is the wrapper let adContainer:UIView = { let view = UIView() view.translatesAutoresizingMaskIntoConstraints = false view.accessibilityLabel = "infiniteScroll_ad_wrapper_tag" return view }() override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) contentView.addSubview(centeredLabel) // Added the wrapper to the item contentView.addSubview(adContainer) // Setup the constraints ... } ... } |
class TableViewInfiniteScrollViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { var tableView:UITableView! ... override func viewDidLoad() { super.viewDidLoad() tableView = UITableView(frame: self.view.bounds, style: .plain) ... // Show the ads let infiniteScrollConfigId = ConfigBuilder.companion.INFINITE_SCROLL_TEST_R89_CONFIG_ID RefineryAdFactory.shared.createInfiniteScroll( configurationID: infiniteScrollConfigId, scrollView: tableView, scrollItemAdWrapperTag: TableViewInfiniteScrollViewController.tag, lifecycleCallbacks: nil ) } ... } |