0
我有一个堆栈来填充一个视图数组。用NSArray和NSMutableArray填充NSStackView
_countViewArray = [[NSArray alloc] init];
_countViewArray = @[self.a.view,self.b.view,self.c.view];
_stackView = [NSStackView stackViewWithViews:_countViewArray];
它工作的很好。 如果我想用一个可变数组替换这个数组,怎么办?
我尝试此代码为“动态”堆栈视图中,并最终转换成可变数组简单数组,但不工作:
_mutableCountViewArray = [[NSMutableArray alloc] init];
[_mutableCountViewArray addObject:@[self.a.view]];
if (caseCondition){
[_mutableCountViewArray addObject:@[self.b.view]];
}
[_mutableCountViewArray addObject:@[self.c.view]];
_countViewArray = [_mutableCountViewArray copy];
_stackView = [NSStackView stackViewWithViews:_countViewArray];
在consolle如果我打印可变数组我有:
(
(
"<NSView: 0x600000121ea0>"
),
(
"<NSView: 0x600000120780>"
,
(
"<NSView: 0x60000a0>"
)
)
我该如何解决?
嘿,谢谢!我不明白多余的感觉。第一个代码块没有可变数组,第二个数组的alloc被理解... – Joannes
@alfioal我的意思是说你可以安全地删除这行'_countViewArray = [[NSArray alloc] init];'(在你使用的情况下第一个片段),因为您在下一行再次为'_countViewArray'指定了一个不同的值......我希望这是有道理的:) – Alladinian
啊,好的!我明白! – Joannes