Ios 将NSArray传递到UIView

Ios 将NSArray传递到UIView,ios,objective-c,uiview,Ios,Objective C,Uiview,我认为这很简单,但它不起作用 我正在尝试将NSArray传递给我的UIView,该视图将使用NIB导入。我将其导入为: DraggableViewBackground *draggableBackground = [[DraggableViewBackground alloc]initWithFrame:frame]; draggableBackground.exampleCardLabels = @[@"Mercedes-Benz", @"BMW", @"Porsche",

我认为这很简单,但它不起作用

我正在尝试将NSArray传递给我的UIView,该视图将使用NIB导入。我将其导入为:

 DraggableViewBackground *draggableBackground = [[DraggableViewBackground alloc]initWithFrame:frame];
    draggableBackground.exampleCardLabels = @[@"Mercedes-Benz", @"BMW", @"Porsche",
                                              @"Opel", @"Volkswagen", @"Audi"];
    [self.ripContainer addSubview:draggableBackground];
在我的可拖动视图背景上ui视图

.h

 @property (retain,nonatomic)NSArray* exampleCardLabels;
.m

    - (id)initWithFrame:(CGRect)frame
        {
        self = [super initWithFrame:frame];
        if (self) {

            [super layoutSubviews];

            NSLog(@"Dish RIP %@", exampleCardLabels);

                   }

         return self;

         }
我当前得到一个null值。我知道这是传递数据时的基本要求,但我不明白为什么这不起作用。

这只是时间安排

在此阶段,尚未设置阵列:

DraggableViewBackground *draggableBackground = [[DraggableViewBackground alloc]initWithFrame:frame];
然而,您正在
initWithFrame
方法中记录数组。稍后在生命周期中记录它


也不要调用
[超级布局子视图]initWithFrame
方法中使用code>。

使您的
init
如下所示:

- (id)initWithFrame:(CGRect)frame andCards:(NSArray *)cards{
    self = [super initWithFrame:frame];
    if (self){
        self.xampleCardLabels = cards;
    }
    return self;
}
叫它

 DraggableViewBackground *draggableBackground = [[DraggableViewBackground alloc]
                                                            initWithFrame: frame 
                                                                 andCards: @[@"Mercedes-Benz", @"BMW", @"Porsche",@"Opel", @"Volkswagen", @"Audi"]];

你得到的是一个空值,具体在哪里?我的NSLog产生了一个空值,我认为这意味着NSArray还没有通过这毫无意义!您正在(id)initWithFrame:(cRect)框架中记录exampleCardLabels值,但尚未对其进行初始化。你认为它会怎样回来values@Allreadyhome您正在设置
exampleCardLabels
后的
NSLog
(位于上面代码中的
initWithFrame:
)@albertamg您的评论实际解释得最好。我的疏忽。谢谢