ios - 指定初始化程序缺少对父类(super class)的指定初始化程序的 super 调用

标签 ios objective-c cocoa

我的代码在这里:

(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.

关于ios - 指定初始化程序缺少对父类(super class)的指定初始化程序的 super 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37434601/

相关文章:

iphone - 将文件从 iphone 上传到 Web 服务器

cocoa - 不要使用 Yosemite 的新透明度

ios - Long 类型的 NSNumber 对象

ios - UIApplicationWillEnterForegroundNotification与application:openURL:sourceApplication:annotation:

ios - 出现键盘时 UIScrollView 为 "lagging"

iphone - 了解 self 的使用

objective-c - 为什么旋转后 UIImageView 的大小会发生变化?

objective-c - 我们如何实现selectionRectsForRange : from UITextInput Protocol?

swift - 归档项目后如何访问添加的 pdf 文件并将其复制到用户文档文件夹中?

objective-c - 使用 Cocoa Frameworks 时的 MacRuby 指针、引用、取消引用