UIAlertController を使用して textField を表示し、電話番号を入力しています。[OK] をクリックしたときに、テキスト フィールドのテキスト コンテンツを変数に格納して、操作を実行できるようにしたいと考えています。コードは次のとおりです。
@IBAction func popup(sender : AnyObject) {
var popupText: String = ""
func config(textField: UITextField!)->Void{
popupText = textField.text
}
var alc: UIAlertController = UIAlertController(title: "Phone", message: "Please enter phone #: ", preferredStyle: UIAlertControllerStyle.Alert)
alc.addTextFieldWithConfigurationHandler(config)
alc.addAction(UIAlertAction(title: "Submit", style: UIAlertActionStyle.Default, handler:{ UIAlertAction in
print(popupText)
self.performSegueWithIdentifier("popupSegue", sender: alc)
}))
alc.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alc, animated: true, completion: nil)
}
popupText にアクセスしてその内容を印刷しようとすると、コンソールに何も表示されないため、空のように見えます。この textField のコンテンツにアクセスする方法、またはその識別子を取得する方法はありますか? (UIAlertController では "alc.textField.text を試せないようです) "config" での処理方法が間違っていると思いますが、このコントローラーのテキスト フィールドにアクセスする方法がまだわかりません。感謝します!