gpt4 book ai didi

swift - Swift 中 PTKView 的初始化问题

转载 作者:行者123 更新时间:2023-11-28 07:15:15 24 4
gpt4 key购买 nike

我正在尝试添加一个 init() ins swift,这样我就可以在类的顶部分配 PTKView,这样我就可以在我的代码中使用它。

我可以在一个函数中创建 var PAymentVIew : PTKView,它工作正常但显然不是全局的。

所以我在类的顶部创建了这个:

class PaymentViewController: UIViewController , PTKViewDelegate {

var PaymentView : PTKView
var button = UIButton.buttonWithType(UIButtonType.System) as UIButton

init(PaymentView : PTKView , button : UIButton) {
self.PaymentView = PaymentView
self.button = button

}

我现在得到的只是一个可怕的错误:

必需的初始化程序“init(coder)”必须由 UIViewController 的子类提供。

任何想法都会很棒。

最佳答案

将此添加到您的 vc 中:

required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

您需要实现此初始化程序(因此需要“必需”关键字)。如果您不想支持它,请留下 fatalError 让人们知道。

init(PaymentView : PTKView , button : UIButton) {
self.PaymentView = PaymentView
self.button = button
super.init()
}

关于swift - Swift 中 PTKView 的初始化问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26610917/

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