###前提・実現したいこと
一つ目のTextFieldにID、二つ目のTextFieldにパスワードを入力できる登録用のAlertを作成しています。
そこで不明な点なのですが、入力された内容を別々の配列に追加するプログラムがよくわかりません。よろしくお願いします。
###ソースコード
swift
1let alert:UIAlertController = UIAlertController(title:"action", 2 message: "alertView", 3 preferredStyle: UIAlertControllerStyle.Alert) 4 5 let cancelAction:UIAlertAction = UIAlertAction(title: "Cancel", 6 style: UIAlertActionStyle.Cancel, 7 handler:{ 8 (action:UIAlertAction!) -> Void in 9 print("Cancel") 10 }) 11 let defaultAction:UIAlertAction = UIAlertAction(title: "OK", 12 style: UIAlertActionStyle.Default, 13 handler:{ 14 (action:UIAlertAction!) -> Void in 15 let textFields:Array<UITextField>? = alert.textFields as Array<UITextField>? 16 if textFields != nil { 17 for textField:UITextField in textFields! { 18 print(textField.text) 19 } 20 } 21 }) 22 alert.addAction(cancelAction) 23 alert.addAction(defaultAction) 24 25 alert.addTextFieldWithConfigurationHandler({(text:UITextField!) -> Void in 26 text.placeholder = "first textField" 27 }) 28 alert.addTextFieldWithConfigurationHandler({(text:UITextField!) -> Void in 29 text.placeholder = "second textField" 30 31 }) 32 presentViewController(alert, animated: true, completion: nil)
###補足情報(言語/FW/ツール等のバージョンなど)
Swift2
Xcode7
回答1件
あなたの回答
tips
プレビュー