我正在尝试convenience init
为 subclassed 创建一个没有参数的UIAlertController
,但它给了我一个错误。
它给了我这个错误:
在调用 self.init 之前在委托初始化程序中使用 self
class AvatarSelectionAlert: UIAlertController {
convenience init(test: String) {
let title = NSLocalizedString("ALERT_CHOOSE_AVATAR_TITLE", comment: "")
let message = NSLocalizedString("ALERT_CHOOSE_AVATAR_MESSAGE", comment: "")
self.init(title: title, message: message, preferredStyle: .ActionSheet)
let selectPremadeAvatarAction = UIAlertAction(title: NSLocalizedString("SELECT_PREMADE_AVATAR", comment: ""), style: .Default) { Void in
}
addAction(selectPremadeAvatarAction)
let chooseFromGalleryAction = UIAlertAction(title: NSLocalizedString("CHOOSE_FROM_GALLERY", comment: ""), style: .Default) { Void in
}
addAction(chooseFromGalleryAction)
let takeNewPictureAction = UIAlertAction(title: NSLocalizedString("TAKE_NEW_PICTURE", comment: ""), style: .Default) { Void in
}
addAction(takeNewPictureAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel) { Void in
}
addAction(cancelAction)
}
}
我也曾尝试self.init()
在打电话给对方之前打电话self.init
,但它崩溃了。
是否可以创建convenience init
没有参数的?