Advanced Usage - Showing banners in UITableView

View original article on our GitHub

If you would like to load a banner into a UITableView instead of a general UIView, follow these instructions:

  1. Make sure that the size of your cell is at least as the size of the banner you would like to show
  2. Declare an STABannerView instance variable in your UITableView class

    var startAppBanner: STABannerView?
  3. Override the cellForRowAtIndexPath function, and add the required code:

    override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell? {
        let reuseIdentifier = "Cell"
        var cell:UITableViewCell? = tableView?.dequeueReusableCellWithIdentifier(reuseIdentifier) as? UITableViewCell
        if !cell {
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: reuseIdentifier)
        if (!startAppBanner) {
          startAppBanner = STABannerView(size: STA_AutoAdSize, autoOrigin: STAAdOrigin_Top, withView: cell, withDelegate: self)
        startAppBanner!.addSTABannerToCell(cell, withIndexPath: indexPath, atIntexPathRow: 2, repeatEach: 8)
        cell!.textLabel.text = "some text"
        cell!.textLabel.backgroundColor = UIColor.clearColor() 
        return cell

    Use the addSTABannerToCell method to set the banner's position and frequency:

    • atIntexPathRow - set the cell where you want to show the banner
    • repeatEach - set repetition frequency

    In the above example, the banner will be displayed at the second cell, and will be repeated each 8 cells.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request