I am trying to isolate iAd initialization code from the main UIViewController as much as possible to achieve an easy integration for my apps in the future. I created AdManager (NSObject) class to deal with iAd setup and initialization. However, I do not know how to set up delegates for objects outside UIViewController which implements these delegate classes. For example:
@interface AppViewController : UIViewController<ADBannerViewDelegate>
and my AdManager would have something like this:
+(void)initAdBannersInView:(UIView*)view andViewController:(UIViewController*)vc{
ADBannerView *iAdBannerView = [[ADBannerView alloc] initWithFrame:CGRectMake(0, -bannerSize.height, bannerSize.width, bannerSize.height)];
iAdBannerView.delegate = vc;
[view addSubview:iAdBannerView];
Error (warning) message is: Assigning to ‘id’ from incompatible type ‘UIViewController’
I may not be very good with this particular situation about delegates, so pardon my possible misunderstanding but is it possible to achive what I need in a similar way? How?
You are defining the
vcargument asUIViewController *. That means you can pass any old view controller in there, not necessarily one that conforms to theADBannerViewDelegateprotocol. You should define thevcargument so that you can only pass view controllers that conform to that protocol in: