5

入力ボタンが押されたときに、アラート ビューのテキスト フィールドからテキストを取得する必要があります。

func inputMsg() {

    var points = ""
    var outOf = ""

    var alertController = UIAlertController(title: "Input View", message: "Please Input Your Grade", preferredStyle: UIAlertControllerStyle.Alert)

    let actionCancle = UIAlertAction(title: "Cancle", style: UIAlertActionStyle.Cancel) { ACTION in

        println("Cacle")
    }
    let actionInput = UIAlertAction(title: "Input", style: UIAlertActionStyle.Default) { ACTION in

        println("Input")
        println(points)
        println(outOf)
    }

    alertController.addAction(actionCancle)
    alertController.addAction(actionInput)
    alertController.addTextFieldWithConfigurationHandler({(txtField: UITextField!) in
        txtField.placeholder = "I got"
        txtField.keyboardType = UIKeyboardType.NumberPad
        points = txtField.text
        })



    alertController.addTextFieldWithConfigurationHandler({(txtField: UITextField!) in
        txtField.placeholder = "Out Of"
        txtField.keyboardType = UIKeyboardType.NumberPad
        outOf = txtField.text
    })
    presentViewController(alertController, animated: true, completion: nil)
}
4

2 に答える 2

3

UIAlertController にはtextFieldsプロパティがあります。それがそのテキストフィールドです。任意のハンドラーがそれを調べることができるため、任意のテキスト フィールドからテキストを取得できます。

于 2014-10-10T18:47:06.833 に答える