我期待創建一個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