I have tried using a singleton class in my app delegate but I haven’t been able to get that to work. I’ve also checked out the iAdSuite examples (particularly the containerBanner example because it seemed to be the most relative) but I can’t figure it out. If there’s a better way to accomplish this without using a singleton class and you can point me in the right direction I’d really appreciate it. Some of my singleton class code is below. Thank you!
@interface App Delegate
@property (assign) iAdController *iadc;
+ (AppDelegate*) sharedApplication;
- (iAdController*)sharedAd;
@end
@implementation AppDelegate
@synthesize iadc;
+ (AppDelegate*) sharedApplication
{
return [[UIApplication sharedApplication] delegate];
}
-(iAdController*)sharedAd
{
if(iadc==nil){
iadc=[iAdController new];
}
return iadc;
}
@interface ViewController
iAdController*iadc=[[AppDelegate sharedApplication] sharedAd];
//here i get an error saying, "initializer element is not a compile-time constant.
Everything is imported correctly. If there’s anything else I should post let me know.
try changing your singleton creation to this:
Obviously change the name of the class.
Whenever you want to use your singleton in any of your viewcontrollers just call it like this:
Dont forget to add
on the header.
EDIT
well it seems i misunderstood your code (forget my answer, you simply want to be able to access your iAdController from everywhere. so just place
Add inside the .m of the ViewController
And inside the
but import the app delegate.h on whichever viewcontroller you want to use it in.
also there shouldnt be a space in the AppDelegate on the @interface