Пример #1
0
        public static UIAlertController PresentTextInputAlert(string title, string description, string placeholder, string text, UIViewController controller, AlertTextInputDelegate action)
        {
            // No, inform the user that they must create a home first
            UIAlertController alert = UIAlertController.Create(title, description, UIAlertControllerStyle.Alert);
            UITextField field = null;

            // Add and configure text field
            alert.AddTextField ((textField) => {
                // Save the field
                field = textField;

                // Initialize field
                field.Placeholder = placeholder;
                field.Text = text;
                field.AutocorrectionType = UITextAutocorrectionType.No;
                field.KeyboardType = UIKeyboardType.Default;
                field.ReturnKeyType = UIReturnKeyType.Done;
                field.ClearButtonMode = UITextFieldViewMode.WhileEditing;

            });

            // Add cancel button
            alert.AddAction(UIAlertAction.Create("Cancel",UIAlertActionStyle.Cancel,(actionCancel) => {
                // Any action?
                if (action!=null) {
                    action(false,"");
                }
            }));

            // Add ok button
            alert.AddAction(UIAlertAction.Create("OK",UIAlertActionStyle.Default,(actionOK) => {
                // Any action?
                if (action!=null && field !=null) {
                    action(true, field.Text);
                }
            }));

            // Display the alert
            controller.PresentViewController(alert,true,null);

            // Return created controller
            return alert;
        }
Пример #2
0
        public static UIAlertController PresentTextInputAlert(string title, string description, string placeholder, string text, UIViewController controller, AlertTextInputDelegate action)
        {
            // No, inform the user that they must create a home first
            UIAlertController alert = UIAlertController.Create(title, description, UIAlertControllerStyle.Alert);
            UITextField       field = null;

            // Add and configure text field
            alert.AddTextField((textField) =>
            {
                // Save the field
                field = textField;

                // Initialize field
                field.Placeholder        = placeholder;
                field.Text               = text;
                field.AutocorrectionType = UITextAutocorrectionType.No;
                field.KeyboardType       = UIKeyboardType.Default;
                field.ReturnKeyType      = UIReturnKeyType.Done;
                field.ClearButtonMode    = UITextFieldViewMode.WhileEditing;
            });

            // Add cancel button
            alert.AddAction(UIAlertAction.Create("Cancel", UIAlertActionStyle.Cancel, (actionCancel) =>
            {
                // Any action?
                if (action != null)
                {
                    action(false, "");
                }
            }));

            // Add ok button
            alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, (actionOK) =>
            {
                // Any action?
                if (action != null && field != null)
                {
                    action(true, field.Text);
                }
            }));

            // Display the alert
            controller.PresentViewController(alert, true, null);

            // Return created controller
            return(alert);
        }