Skip to content

7. Multiple Text Fields Alerts

Gabriel Theodoropoulos edited this page Apr 17, 2019 · 1 revision

Multiple text fields alerts

The following method that presents an alert controller with multiple text fields is quite similar to the one presented in the previous part. The greatest difference that you'll notice is that instead of dealing with a single text field only, we are dealing with a collection of text fields:

GTAlertCollection.shared.presentMultipleTextFieldsAlert(withTitle: "Input Data", message: "Lots of stuff to type here...", doneButtonTitle: "OK", cancelButtonTitle: "Cancel", numberOfTextFields: 5, configurationHandler: { (textFields, didFinishConfiguration) in

    if let textFields = textFields {
        // Configure all textfields one by one.

        // Call the following to allow alert to be presented.
        didFinishConfiguration()
    }

}) { (textFields) in
    if let textFields = textFields {
        // Do something with the textfields.

        for i in 0..<textFields.count {
            print(textFields[i].text ?? "")
        }
    }
}

There's an additional parameter in this method, called numberOfTextFields. Use it to specify the number of text fields you want to appear on the alert.

Multiple textfields alert

All rules previously discussed apply here too, so make sure you read that part as well.