Xcode Obj - C - retrieve user inputed text from Alert Box IOS8

吃可爱长大的小学妹 提交于 2019-11-29 18:46:42

Try this:

//Creates the alert box
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Congratulations"
message:@"You Have The High Score, Enter Your Name"
preferredStyle:UIAlertControllerStyleAlert];
NSString *Fullname = @""
//Adds a text field to the alert box
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField)
{
textField.placeholder = NSLocalizedString(@"Enter Full Name", @"Fullname");
}];

[self presentViewController:alertController animated:YES completion:nil];
//Creates a button with actions to perform when clicked
UIAlertAction *SaveAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"SAVE",@"Save Action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
//Stores what has been inputted into the NSString Fullname
UITextField * textField = alertController.textFields.firstObject;
Fullname = textField.text
NSLog(@"Name Stored %@",Fullname);


[self performSegueWithIdentifier:@"NoNextSlide" sender:self];

}];

[alertController addAction:SaveAction];

What you call FullName isn't actually a string. It's a UITextField. If you want the inputed name, juste call the text property from this textfield.

UITextField *nameField = alertController.textFields.firstObject;
NSString *Fullname = nameField.text;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!