Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am planning to have different adbanners on all my viewcontrollers/screens and I was wondering whether creating a subclass for each viewcontroller is the **best** possible way of doing that ? I have looked everywhere for an answer for this but can seem to find one...

The reason I am asking about subclass (which is a long process so far as I have atleast 20 viewcontrollers) is because when i try to write code for the adbanner within the original .h or .m file I get a **duplicate of class error .... 

How can I go about correcting this please?**

**this is the iAD code I have within the original .h file**

    #import <UIKit/UIKit.h>
    #import <iAd/iAd.h>

    @interface ViewController : UIViewController <ADBannerViewDelegate>
    @property (weak, nonatomic) IBOutlet ADBannerView *banner;

    @end


**this is the iAD code I have within the original .m file**

    #import "ViewController.h"

    @interface ViewController ()

    @end

    @implementation ViewController

    - (void)viewDidLoad
    {
    [super viewDidLoad];
    self.banner.delegate = self;
    }

    - (void) viewDidLayoutSubviews {
    if (self.banner.bannerLoaded) {
        CGRect contentFrame = self.view.bounds;
        CGRect bannerFrame = self.banner.frame;
        contentFrame.size.height -= self.banner.frame.size.height;
        bannerFrame.origin.y = contentFrame.size.height;
        self.banner.frame = bannerFrame;
    }
    }

    - (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

    - (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
    {
    NSLog(@"bannerViewActionShouldBegin");
    return YES;
    }

    - (void)bannerViewDidLoadAd:(ADBannerView *)banner
    {
    NSLog(@"bannerViewDidLoadAd");
    }

    - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
    {
    NSLog(@"didFailToReceiveAdWithError");
    }

    - (void)bannerViewActionDidFinish:(ADBannerView *)banner {
    NSLog(@"bannerViewActionDidFinish");
    }

    @end


**this is the iAD code I have within the new subclass of my second viewcontroller .h file**

    #import "ViewController.h"
    #import <UIKit/UIKit.h>
    #import <iAd/iAd.h>


    @interface ViewController2ad : UIViewController <ADBannerViewDelegate>
    @property (weak, nonatomic) IBOutlet ADBannerView *banner2;

    @end

**and for the .m file sublass, i was just gonna copy some of the code i wrote for the adbanner in the original .m file into the subclass .m file for the second viewcontroller and change up the appropriate values fore instance the adbanner in the second viewcontroller is named *banner2 - to add a subclass i right clicked on the project name then add file the chose the objective c class which after adding the files gave me the two new .h and .m subclass files.**
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900