gpt4 book ai didi

ios - UIView 的 initWithFrame

转载 作者:行者123 更新时间:2023-11-28 19:42:56 24 4
gpt4 key购买 nike

我在我的 UIView 中声明了一个属性,如下所示:
@property (nonatomic, strong) NSMutableArray *finishedLines;

我初始化使用:

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
//[self setFinishedLines:[[NSMutableArray alloc] init]];
[self setBackgroundColor:[UIColor grayColor]];

如果我取消注释 [self setFinishedLines..] 会有什么区别?

我声明属性的时候不是已经初始化了吗?

如果我取消注释但我不明白其中的逻辑,我会得到不同的结果。

最佳答案

objective-c 中的属性不会自动初始化。

您必须在构造函数中分配和初始化它(或使用 new,它基本上是 alloc 和 init 的快捷方式)。

   self.finishedLines = [[NSMutableArray alloc] init]];

关于ios - UIView 的 initWithFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33629770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com