我期待创建一个UIAlertController
的自定义子类。 如果我理解正确,我需要在子类初始化期间的某处调用super.init(title...
。初始化UIAlertController的子类
但我一直遇到指定的初始值设定项的问题。我已阅读文档,无法弄清楚如何使其工作。这里是我的代码(注意代码中的注释):
class AccountInfoActionSheet: UIAlertController {
required init?(coder aDecoder: NSCoder) { //xcode says I need this
super.init(coder: aDecoder) //it also says I need to call a designated initializers so here it is
super.init(title: "Info", message: "Heres the Info", preferredStyle: .actionSheet) //but now I can't call this initializer
fatalError("init(coder:) has not been implemented")
}
}
编辑:由于UIAlertController
不能被继承我只是创建了返回需要它的视图控制器内的正确配置UIAlertController
的功能。
可以,但你不应该。 – Abizern
@Abizern:是吗?你能告诉我如何或在哪里可以阅读与之相关的文件。 – Amit
https://stackoverflow.com/a/45895316/41116 – Abizern