gpt4 book ai didi

ios - initWithNibName 不实现父类(super class) - Swift

转载 作者:行者123 更新时间:2023-11-28 10:02:27 26 4
gpt4 key购买 nike

我正在尝试实现 Objective-C equiv。下面是使用 nib 调用 View Controller 时的情况。

Objective-C :

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.modalPresentationStyle = UIModalPresentationCustom;
self.transitioningDelegate = self;
}
return self;
}

到目前为止,这是我在 swift 中的位置:

override init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

self.modalPresentationStyle = UIModalPresentationStyle.Custom
self.transitioningDelegate = self
}

但是我一直收到这个错误:

Class "ViewController" does not implement its superclass's required members

我以为上面的初始化方法需要成员?

编辑 - 下面详细介绍: Class does not implement its superclass's required members

最佳答案

您必须实现基类所需的初始值设定项。在您的情况下,您应该将以下代码添加到您的 VC 类中:

required init(coder aDecoder: NSCoder!) {
super.init(coder: aDecoder)
}

自 Beta 5 以来:

The required modifier is written before every subclass implementation of a required initializer. Required initializers can be satisfied by automatically inherited initializers.

备注:

required init(coder aDecoder: NSCoder!) { ... } 仅当您覆盖类中的至少一个 init 方法时才应添加。

关于ios - initWithNibName 不实现父类(super class) - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25267907/

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