gpt4 book ai didi

ios - 从 initWithCoder : 调用另一个 init 时指定的初始化程序警告

转载 作者:行者123 更新时间:2023-11-29 11:46:31 24 4
gpt4 key购买 nike

我正在处理继承的代码库并尝试解决以下警告:

Designated initializer should only invoke a designated initializer on 'super'

Designated initializer missing a 'super' call to a designated initializer of the super class

代码是:

- (id)initWithCoder:(NSCoder *)aDecoder {
self = [self initWithFrame:[CDCUtility getScreenBounds]]; //switching to super breaks
if (self) {
}
return self;
}

- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setArray:[NSMutableArray new]];
[self setButtonArray:[NSMutableArray new]];
_graphicEQ = [[CDCEffectsGraphicEQ alloc] initWithFrame:CGRectMake((1024 / 2) - (811 / 2), 60, 860, 255)];
[self addSubview:_graphicEQ];
[_graphicEQ setDelegate:self];
[self addBypassButtonToView];
[self addFlatButtonToView];
[self addScrollView];
}
return self;
}

因此据我所知,开发人员覆盖了父类(super class) initWithCoder:(这是一个 UIView)以允许加载自定义 UI,并传入此initWithFrame: 使用自定义参数创建 View 的参数。

我看到有人说将 initWithCoder: 中的 [self initWithFrame:]' 更改为 [super initWithFrame:] 这确实解决了警告,但是它也绕过了调用此处正确加载 View 所需的功能。

它按原样运行良好;我只是想减少所有可能的警告,所以我想知道是否可以通过更改来解决这个问题?

最佳答案

试试这个:

- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self designatedInitializer];
}
return self;
}

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

- (void) designatedInitializer {
[self setArray:[NSMutableArray new]];
[self setButtonArray:[NSMutableArray new]];
_graphicEQ = [[CDCEffectsGraphicEQ alloc] initWithFrame:CGRectMake((1024 / 2) - (811 / 2), 60, 860, 255)];
[self addSubview:_graphicEQ];
[_graphicEQ setDelegate:self];
[self addBypassButtonToView];
[self addFlatButtonToView];
[self addScrollView];
}

关于ios - 从 initWithCoder : 调用另一个 init 时指定的初始化程序警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43541555/

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