如何为2个UIView使用单个IB插座

时间:2019-08-06 23:11:45

标签: ios objective-c

我目前正在开发一个显示广告的应用程序。主视图控制器具有2个UIView,它们充当广告视图的容器,这些视图将在加载时传递。但是,我使用的API仅使用一个“ adContainer”作为参数,因此尝试使用名为adContainer的IBOutlet集合,该集合将这两个UIView(adContainer1和adContainer2)都链接到了它。我标记了每个标记,以便在尝试加载广告时在主视图控制器上进行迭代,可以遍历IBOutlet集合中的adContainers并根据对象的标记分别请求每个adContainer。我被抛出此错误:

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UIView countByEnumeratingWithState:objects:count:]:无法识别的选择器已发送到实例

这是我的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

这是我怀疑会抛出错误的viewController.m中的函数:

- (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];

        }
}
}

请帮助!预先谢谢你!

1 个答案:

答案 0 :(得分:1)

按照你的说法,我自己没有报告错误;可能是您的xib电缆设置不正确。
您可以参考以下内容:   "countByEnumeratingWithState:objects:count:" Error