【发布时间】:2017-04-21 11:26:56
【问题描述】:
我正在处理继承的代码库并尝试解决以下警告:
指定的初始化器应该只在“super”上调用一个指定的初始化器
指定的初始化程序缺少对超类的指定初始化程序的“超级”调用
代码是:
- (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;
}
所以据我所知,开发人员覆盖了超类initWithCoder:(这是一个UIView)以允许加载自定义UI,并使用自定义参数传入这个initWithFrame:参数来创建视图.
我看到有人说将initWithCoder: 中的[self initWithFrame:]' 更改为[super initWithFrame:],这确实解决了警告,但它也绕过了调用此处正确加载视图所需的功能。
它可以正常工作;我只是想减少所有可能的警告,所以我想知道是否可以进行更改来解决这个问题?
【问题讨论】:
标签: ios objective-c designated-initializer