0

I'm currently developing an application that displays ads. The main view controller has 2 UIViews that act as containers for the ad views that will be passed in when they are loaded. However, I'm using an API that only takes a single "adContainer" as a parameter, so tried using an IBOutlet Collection called adContainer that has each of these 2 UIViews (adContainer1 and adContainer2) linked to it. I tagged each of these so that on the main view controller when I try to load an ad, I can iterate through the adContainers in the IBOutlet Collection and request each adContainer individually based on the object's tag. I'm being thrown this error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance

Here is the code for my viewController.h :

#import <UIKit/UIKit.h>
#import "MPAdView.h"
#import "MPViewController.h"

@class MPAdInfo;

@interface MPSmaatoScrollBannerAdDetailViewController : 
UIViewController <MPAdViewDelegate>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@property (weak, nonatomic) IBOutlet UILabel *IDLabel;

@property (weak, nonatomic) IBOutlet UILabel *failLabel;

@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *spinner;

@property (strong, nonatomic) IBOutletCollection(UIView) NSArray 
*adViewContainer;

- (id)initWithAdInfo:(MPAdInfo *)info;

@end

And here is the function in my viewController.m that I suspect is throwing the error:

- (void)configureAd
{

for (UIView *ad in _adViewContainer) {
        if (ad.tag == 1) {

            self.adView1 = [[MPSampleAppInstanceProvider sharedProvider] buildMPAdViewWithAdUnitID:self.info.ID
                                                                                              size:ad.bounds.size];
            self.adView1.delegate = self;
            self.adView1.accessibilityLabel = @"smaato banner";
            self.adView1.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            [ad addSubview:self.adView1];

            [self.adView1 stopAutomaticallyRefreshingContents];

        } else if (ad.tag == 2) {

            self.adView2 = [[MPSampleAppInstanceProvider sharedProvider] buildMPAdViewWithAdUnitID:self.info.ID
                                                                                              size:ad.bounds.size];
            self.adView2.delegate = self;
            self.adView2.accessibilityLabel = @"smaato banner";
            self.adView2.autoresizingMask = UIViewAutoresizingFlexibleWidth;
            [ad addSubview:self.adView2];

            [self.adView2 stopAutomaticallyRefreshingContents];

        }
}
}

Please help! Thank you in advance!

James M
  • 21
  • 7

1 Answers1

1

According to the way you said, I did not report an error myself; it may be that your xib cable is not set correctly.
You can refer to this: "countByEnumeratingWithState:objects:count:" Error

安Alex
  • 11
  • 1