からshowAlertView
メソッドを呼び出します。
func popup(caller:UIViewController, style:UIAlertControllerStyle? = UIAlertControllerStyle.alert,
title:String, message:String, buttonTexts:[String], buttonStyles:([UIAlertActionStyle?])? = nil,
handlers:[((UIAlertAction) -> Void)?], animated:Bool? = nil, completion: (() -> Void)? = nil) {
let alert = UIAlertController(title: title, message: message, preferredStyle: style!)
for i in 0..<buttonTexts.count {
alert.addAction(UIAlertAction(title: buttonTexts[i],
style: (buttonStyles == nil || i >= buttonStyles!.count || buttonStyles![i] == nil ?
UIAlertActionStyle.default : buttonStyles![i]!),
handler: (i >= handlers.count || handlers[i] == nil ? nil : handlers[i]!)))
}
caller.present(alert, animated: animated != nil ? animated! : true, completion: completion)
}
- シングル機能が
Alert
を与えます既定ではにオプションで使用できます。
- アレイ
buttonTexts
,buttonStyles
およびhandlers
は、要件ごとに異なるサイズであってもよい。
Actions
にスタイルを付けることができます。
Animated
を指定できます。
- オプション
block
は、プレゼンテーションが終了したときに実行するように指定できます。
使用法:
popup(caller: self, style: UIAlertControllerStyle.alert,
title: "Title", message: "Message",
buttonTexts: ["Destructive", "Cancel", "OK"],
buttonStyles: [UIAlertActionStyle.destructive, UIAlertActionStyle.cancel],
handlers: [nil], animated: false)
私はタイプ・ビュー・コントローラの別の引数を追加し、そのコントローラを使用してアラートを提示します。 – Desdenova
あなたはパラメータとしてプレゼンターも要求する必要があります。 – holex