Appearance
Banner Management in Recycled Views
When integrating banners within a collection view or any container that recycles views (e.g., UICollectionView, UITableView), it is important to manage the lifecycle of each banner instance correctly to avoid unnecessary resource usage and improve performance.
The SDK provides a method for this management:
swift
/// Method to activate/deactivate banner
/// - Parameters:
/// - active: `true` - banner should restart ad downloading logic,
/// `false` - banner should stop ad downloading logic and free memory resources
public func setActive(_ active: Bool)Calling setActive(true) will reactivate and reload the banner ad, while setActive(false) will stop its ad loading and release associated resources. Use this method with caution—not every banner placement needs to be reloaded every time it goes outside of the viewport. Frequent reloading may negatively affect performance, network usage, and ad delivery.
Guidelines:
- Call
setActive(false)when a banner view is about to be recycled or leaves the visible viewport for an extended period. - Call
setActive(true)when a recycled banner reappears in the viewport and should attempt to show an ad again. - For banners that remain persistently visible, you do not need to toggle their active state.
Example:
swift
func collectionView(_ collectionView: UICollectionView, didEndDisplaying cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if let bannerCell = cell as? BannerCell {
bannerCell.bannerView.setActive(false)
}
}
func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
if let bannerCell = cell as? BannerCell {
bannerCell.bannerView.setActive(true)
}
}Note:
Only usesetActive(_:)for banners embedded in recycled views or dynamic layouts. For static placements (e.g., banners that do not scroll off screen), simply load the ad once without manually toggling activity.
WARNING
If you are unsure about when and how to use setActive(_:) for your specific setup, please reach out to your Ringier Advertising partner manager for guidance.

