本文整理汇总了C#中UIAlertView.GetTextField方法的典型用法代码示例。如果您正苦于以下问题:C# UIAlertView.GetTextField方法的具体用法?C# UIAlertView.GetTextField怎么用?C# UIAlertView.GetTextField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIAlertView
的用法示例。
在下文中一共展示了UIAlertView.GetTextField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlatformShow
private static Task<string> PlatformShow(string title, string description, string defaultText, bool usePasswordMode)
{
tcs = new TaskCompletionSource<string>();
UIApplication.SharedApplication.InvokeOnMainThread(delegate
{
alert = new UIAlertView();
alert.Title = title;
alert.Message = description;
alert.AlertViewStyle = usePasswordMode ? UIAlertViewStyle.SecureTextInput : UIAlertViewStyle.PlainTextInput;
alert.AddButton("Cancel");
alert.AddButton("Ok");
UITextField alertTextField = alert.GetTextField(0);
alertTextField.KeyboardType = UIKeyboardType.ASCIICapable;
alertTextField.AutocorrectionType = UITextAutocorrectionType.No;
alertTextField.AutocapitalizationType = UITextAutocapitalizationType.Sentences;
alertTextField.Text = defaultText;
alert.Dismissed += (sender, e) =>
{
if (!tcs.Task.IsCompleted)
tcs.SetResult(e.ButtonIndex == 0 ? null : alert.GetTextField(0).Text);
};
// UIAlertView's textfield does not show keyboard in iOS8
// http://stackoverflow.com/questions/25563108/uialertviews-textfield-does-not-show-keyboard-in-ios8
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
alert.Presented += (sender, args) => alertTextField.SelectAll(alert);
alert.Show();
});
return tcs.Task;
}
示例2: Display
public void Display (string body, string title, GoalsAvailable goalAvailable, string cancelButtonTitle, string acceptButtonTitle = "", Action<GoalsAvailable, int> action = null)
{
UIAlertView alert = new UIAlertView();
alert.Title = title;
alert.AddButton(acceptButtonTitle);
alert.AddButton(cancelButtonTitle);
alert.Message = body;
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
alert.GetTextField(0).KeyboardType=UIKeyboardType.NumberPad;
const int maxCharacters =7;
alert.GetTextField(0).ShouldChangeCharacters = (textField, range, replacement) =>
{
var newContent = new NSString(textField.Text).Replace(range, new NSString(replacement)).ToString();
int number;
return newContent.Length <= maxCharacters && (replacement.Length == 0 || int.TryParse(replacement, out number));
};
alert.Clicked += (object s, UIButtonEventArgs ev) =>
{
if(action != null)
{
if(ev.ButtonIndex ==0)
{
string input = alert.GetTextField(0).Text;
int goalValue;
int.TryParse(input, out goalValue);
action.Invoke(goalAvailable, goalValue);
}
}
};
alert.Show();
}
示例3: addNewItem
public void addNewItem(object sender, EventArgs e)
{
UIAlertView alert = new UIAlertView(
NSBundle.MainBundle.LocalizedString("Create an Asset Type", "Create Asset Type"),
NSBundle.MainBundle.LocalizedString("Please enter a new asset type", "Please Enter"),
null,
NSBundle.MainBundle.LocalizedString("Cancel", "Cancel"),
new string[]{NSBundle.MainBundle.LocalizedString("Done", "Done")});
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
UITextField alerttextField = alert.GetTextField(0);
alerttextField.KeyboardType = UIKeyboardType.Default;
alerttextField.Placeholder = NSBundle.MainBundle.LocalizedString("Enter a new asset type", "Enter New");
alert.Show(); // Use for silver challenge
alert.Clicked += (object avSender, UIButtonEventArgs ave) => {
if (ave.ButtonIndex == 1) {
Console.WriteLine("Entered: {0}", alert.GetTextField(0).Text);
BNRItemStore.addAssetType(alert.GetTextField(0).Text);
TableView.ReloadData();
NSIndexPath ip = NSIndexPath.FromRowSection(BNRItemStore.allAssetTypes.Count-1, 0);
this.RowSelected(TableView, ip);
} else {
this.NavigationController.PopViewController(true);
}
};
}
示例4: LoadView
public override void LoadView() {
base.LoadView();
_MapView = new MapView() {
MyLocationEnabled = true,
};
_Markers.ForEach(mmi => mmi.Map = _MapView);
_MapView.Settings.RotateGestures = false;
_MapView.Tapped += (object tapSender, GMSCoordEventArgs coordEventArgs) => {
UIAlertView nameInputAlertView = new UIAlertView("Add New Marker", "", null, "Cancel", new[] { "Add" }) {
AlertViewStyle = UIAlertViewStyle.PlainTextInput,
};
UITextField nameTextField = nameInputAlertView.GetTextField(0);
nameTextField.Placeholder = "Marker name";
nameTextField.BecomeFirstResponder();
nameInputAlertView.Dismissed += (sender, e) => {
if (e.ButtonIndex != nameInputAlertView.CancelButtonIndex) {
MarkerInfo newMarkerInfo = new MarkerInfo() {
Latitude = coordEventArgs.Coordinate.Latitude,
Longitude = coordEventArgs.Coordinate.Longitude,
Name = nameTextField.Text,
};
NewMarkerCreated(this, new MarkerAddedEventArgs(newMarkerInfo));
}
};
nameInputAlertView.Show();
};
View = _MapView;
}
示例5: SignIn
async Task<bool> SignIn()
{
var tcs = new TaskCompletionSource<bool> ();
var alert = new UIAlertView ("Please sign in", "", null, "Cancel", "Ok");
alert.AlertViewStyle = UIAlertViewStyle.SecureTextInput;
var tb = alert.GetTextField(0);
tb.ShouldReturn = (t)=>{
alert.DismissWithClickedButtonIndex(1,true);
signIn(tcs,tb.Text);
return true;
};
alert.Clicked += async (object sender, UIButtonEventArgs e) => {
if(e.ButtonIndex == 0)
{
tcs.TrySetResult(false);
alert.Dispose();
return;
}
var id = tb.Text;
signIn(tcs,id);
};
alert.Show ();
return await tcs.Task;
}
示例6: Login
public override void Login(LoginConfig config) {
UITextField txtUser = null;
UITextField txtPass = null;
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) {
var dlg = UIAlertController.Create(config.Title ?? String.Empty, config.Message, UIAlertControllerStyle.Alert);
dlg.AddAction(UIAlertAction.Create(config.OkText, UIAlertActionStyle.Default, x => config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, true))));
dlg.AddAction(UIAlertAction.Create(config.CancelText, UIAlertActionStyle.Default, x => config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, false))));
dlg.AddTextField(x => {
txtUser = x;
x.Placeholder = config.LoginPlaceholder;
x.Text = config.LoginValue ?? String.Empty;
});
dlg.AddTextField(x => {
txtPass = x;
x.Placeholder = config.PasswordPlaceholder;
x.SecureTextEntry = true;
});
this.Present(dlg);
}
else {
var dlg = new UIAlertView {
AlertViewStyle = UIAlertViewStyle.LoginAndPasswordInput,
Title = config.Title,
Message = config.Message
};
txtUser = dlg.GetTextField(0);
txtPass = dlg.GetTextField(1);
txtUser.Placeholder = config.LoginPlaceholder;
txtUser.Text = config.LoginValue ?? String.Empty;
txtPass.Placeholder = config.PasswordPlaceholder;
dlg.AddButton(config.OkText);
dlg.AddButton(config.CancelText);
dlg.CancelButtonIndex = 1;
dlg.Clicked += (s, e) => {
var ok = ((int)dlg.CancelButtonIndex != (int)e.ButtonIndex);
config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, ok));
};
this.Present(dlg);
}
}
示例7: Dismissed
public override void Dismissed(UIAlertView alertView, int buttonIndex)
{
if (buttonIndex == alertView.CancelButtonIndex)
cancelAction();
else if (alertView.AlertViewStyle == UIAlertViewStyle.SecureTextInput)
okActionOfString(alertView.GetTextField(0).Text);
else
okAction();
}
示例8: Login
public override void Login(LoginConfig config) {
this.Dispatch(() => {
var dlg = new UIAlertView { AlertViewStyle = UIAlertViewStyle.LoginAndPasswordInput };
var txtUser = dlg.GetTextField(0);
var txtPass = dlg.GetTextField(1);
txtUser.Placeholder = config.LoginPlaceholder;
txtUser.Text = config.LoginValue ?? String.Empty;
txtPass.Placeholder = config.PasswordPlaceholder;
txtPass.SecureTextEntry = true;
dlg.Clicked += (s, e) => {
var ok = (dlg.CancelButtonIndex != e.ButtonIndex);
config.OnResult(new LoginResult(txtUser.Text, txtPass.Text, ok));
};
dlg.Show();
});
}
示例9: Display
public void Display (string body, string title, BarriersAvailable barrierAvailable, string cancelButtonTitle, string acceptButtonTitle = "", Action<BarriersAvailable, string> action = null)
{
UIAlertView alert = new UIAlertView();
alert.Title = title;
alert.AddButton(acceptButtonTitle);
alert.AddButton(cancelButtonTitle);
alert.Message = body;
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
var textField = alert.GetTextField (0);
CGRect frameRect = textField.Frame;
CGSize size = new CGSize (150, 60);
frameRect.Size = size;
textField.Frame = frameRect;
alert.Clicked += (object s, UIButtonEventArgs ev) =>
{
if(action != null)
{
if(ev.ButtonIndex ==0)
{
string input = alert.GetTextField(0).Text;
action.Invoke(barrierAvailable, input);
}
}
};
alert.Show();
// UIAlertController alert = UIAlertController.Create (title, body, UIAlertControllerStyle.Alert);
//
// alert.AddAction (UIAlertAction.Create (acceptButtonTitle, UIAlertActionStyle.Default, action2 => {
// //SendComment(alert.TextFields[0].Text);
// string input = alert.TextFields[0].Text;
// action.Invoke(barrierAvailable, input);
// }));
//
// alert.AddAction (UIAlertAction.Create (cancelButtonTitle, UIAlertActionStyle.Cancel, null));
// alert.AddTextField ((field) => {
// field.Placeholder = title;
// });
//
// alert.
}
示例10: PromptTextBox
public Task<string> PromptTextBox(string title, string message, string defaultValue, string okTitle)
{
var tcs = new TaskCompletionSource<string>();
var alert = new UIAlertView();
alert.Title = title;
alert.Message = message;
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
var cancelButton = alert.AddButton("Cancel");
var okButton = alert.AddButton(okTitle);
alert.CancelButtonIndex = cancelButton;
alert.GetTextField(0).Text = defaultValue;
alert.Clicked += (s, e) =>
{
if (e.ButtonIndex == okButton)
tcs.SetResult(alert.GetTextField(0).Text);
else
tcs.SetCanceled();
};
alert.Show();
return tcs.Task;
}
示例11: AskForString
public void AskForString(string message, string title, System.Action<string> returnString)
{
Helpers.EnsureInvokedOnMainThread (() => {
var alertView = new UIAlertView (title ?? string.Empty, message, null, "OK", "Cancel");
alertView.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
alertView.Clicked += (sender, e) => {
var text = alertView.GetTextField(0).Text.Trim();
if(e.ButtonIndex == 0 && !string.IsNullOrWhiteSpace(text))
returnString (text);
};
alertView.Show ();
});
}
示例12: Save
private void Save()
{
/*
_messageDb.SaveMessage(textViewMessage.Text);
*/
var alert = new UIAlertView("Enter Password", "Password", null, "OK", null) {
AlertViewStyle = UIAlertViewStyle.SecureTextInput
};
alert.Clicked += (s, a) => {
_messageDb.Password = alert.GetTextField(0).Text;
_messageDb.SaveMessage(textViewMessage.Text);
};
alert.Show();
}
示例13: EnterTextMessage
public void EnterTextMessage(string title, string message, Action<string> completed)
{
var alert = new UIAlertView(title, message, null, "Enter", "Cancel")
{
AlertViewStyle = UIAlertViewStyle.PlainTextInput
};
alert.Dismissed += (sender2, args) =>
{
if (args.ButtonIndex != 0)
return;
completed(alert.GetTextField(0).Text.Trim());
};
alert.Show();
}
示例14: Input
public void Input(string message, Action<bool, string> answer, string placeholder = null, string title = null, string okButton = "OK", string cancelButton = "Cancel")
{
UIApplication.SharedApplication.InvokeOnMainThread(() =>
{
var input = new UIAlertView(title ?? string.Empty, message, null, cancelButton, okButton);
input.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
var textField = input.GetTextField(0);
textField.Placeholder = placeholder;
if (answer != null)
{
input.Clicked +=
(sender, args) =>
answer(input.CancelButtonIndex != args.ButtonIndex, textField.Text);
}
input.Show();
});
}
示例15: HandleCreateSheetClicked
void HandleCreateSheetClicked (object sender, UIButtonEventArgs e)
{
var actionSheet = (UIActionSheet)sender;
if (e.ButtonIndex != actionSheet.CancelButtonIndex) {
creatingFolder = e.ButtonIndex > 0;
string title = creatingFolder ? "Create folder" : "Create a file";
var alert = new UIAlertView (title, "", null, "Cancel", new string[] {"Create"});
alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput;
alert.Clicked += (s, a) => {
if (a.ButtonIndex != alert.CancelButtonIndex) {
string input = alert.GetTextField (0).Text;
CreateAt (input);
}
DispatchQueue.DefaultGlobalQueue.DispatchAsync (() => LoadFiles ());
};
alert.Show ();
}
}