0
私は唯一の三つのボタンで自分のカスタムアラートのコントローラを持っていると私はをキャンセル三つのボタンがあり、を送信し、はを追加しますが、私は以下のような単一完了ハンドラを持っていると思います。使用単一完了ハンドラグローバル
self.showAlertWithButtonClicked(clickedButton: { (clickedButton) -> Void in
//check the button index by clickedButton.tag
})
しかし、私は私のAlertControllerクラスにこれを実装しようとしたとき、それは私を許可していません。以下 は私のMyAlertControllerワイヤーフレームコードです:
class MyAlertController: UIViewController {
typealias CompletionHandler = (_ clickedButton: UIButton) -> Void
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func showAlertWithButtonClicked(clickedButton: @escaping (MultipleMethodRunningHandle)) {
//Do what you want
}
func pressedCancelButton(button: UIButton) {
//At this point compiler doesn't allow me to use that completionHandler globally in the class
button.tag = 0
clickedButton(button)
}
func pressedSendButton(button: UIButton) {
//At this point compiler doesn't allow me to use that completionHandler globally in the class
button.tag = 1
clickedButton(button)
}
func pressedAddButton(button: UIButton) {
//At this point compiler doesn't allow me to use that completionHandler globally in the class
button.tag = 2
clickedButton(button)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
私は、クラス全体でこれらのハンドラにアクセスできるように、どのように私はこれを達成することができます。