首页 > 解决方案 > Swift 创建自定义警报控制器初始化程序

问题描述

我正在实施 UIAlertController 以在重置用户密码时进行确认。我创建了一个继承自 UIAlertController 的自定义类。我还为我在文档中看到的类进行了初始化。

import UIKit

class PasswordResetConfirmationViewController: UIAlertController {

    init() {
        super.init(title: "Are you sure you would like to reset your password?",message: "",preferredStyle: .alert)
    }

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

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }
}

奇怪的是我得到这个错误必须在 xcode 中调用超类“UIAlertController”的指定初始化程序。这是来自 UIAlertController 的初始化

init(title: String?, 
         message: String?, 
  preferredStyle: UIAlertController.Style)

我不确定是什么在 xcode 中产生了这个错误,任何帮助都会很棒。

标签: iosswiftuialertcontroller

解决方案


推荐阅读