Follow

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. Declare an STABannerView instance variable in your UITableView class

    @interface YourViewController ()
    {
       STABannerView* bannerview;
    }
    @end
  2. Override the cellForRowAtIndexPath method, and add the required code:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
       static NSString *CellIdentifier = @"Cell";
       UITableViewCell *cell=nil;
       cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
       if (cell == nil)  {
           cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier]; 
       }
    
    
       // ADD THE FOLLOWING LINES
       if(bannerview == nil)
       {
           bannerview = [[STABannerView alloc] initWithSize:STA_AutoAdSize autoOrigin:STAAdOrigin_Top  withView:cell withDelegate:self]; 
       }
    
       [bannerview addSTABannerToCell:cell withIndexPath:indexPath atIntexPathRow:2 repeatEach:8];
    
       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

Comments

  • Avatar
    ishwar lal Janwa
    it is not work