ios – 指定的初始化程序缺少对超类的指定初始化程序的超级调用

我的代码在这里:

(instancetype)initWithFrame:(CGRect)frame
{
self = [[[NSBundle mainBundle] loadNibNamed:@"LSCouponADView" owner:Nil options:nil] objectAtIndex:0];
if (self) {

}

    return self;
}

然后xcode发出警告

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

当我建造它.

最佳答案 您需要在此方法中添加此行.

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

}
return self;

Apple Doc起.

指定初始化程序

The initializer of a class that takes the full complement of initialization parameters is usually the designated initializer. The designated initializer of a subclass must invoke the designated initializer of its superclass by sending a message to super. The convenience (or secondary) initializers—which can include init—do not call super. Instead they call (through a message to self) the initializer in the series with the next most parameters, supplying a default value for the parameter not passed into it. The final initializer in this series is the designated initializer.

点赞