Xcode Obj - C - 从Alert Box IOS8检索用户输入的文本 [英] Xcode Obj - C - retrieve user inputed text from Alert Box IOS8
本文介绍了Xcode Obj - C - 从Alert Box IOS8检索用户输入的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码,允许用户将其全名输入到警告框中;
i have the following code which will allow a user to input their full name into an alert box;
//Creates the alert box
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Congratulations"
message:@"You Have The High Score, Enter Your Name"
preferredStyle:UIAlertControllerStyleAlert];
//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
NSString *Fullname = alertController.textFields.firstObject;
NSLog(@"Name Stored %@",Fullname);
[self performSegueWithIdentifier:@"NoNextSlide" sender:self];
}];
[alertController addAction:SaveAction];
你会注意到这一点;
NSLog(@"Name Stored %@",Fullname);
这将返回以下内容;
2015-03-03 11:54:19.374 Master Game[1864:26681] Name Stored <_UIAlertControllerTextField: 0x7f9cf61ed780; frame = (4 4; 229 16); text = 'Shaun'; clipsToBounds = YES; opaque = NO; gestureRecognizers = <NSArray: 0x7f9cf6084bd0>; layer = <CALayer: 0x7f9cf61854b0>>
如何从那里获得输入的'Shaun'以便我可以保存并使用它将来?
How do i get just the inputted 'Shaun' from there so that i can save it and use it in future?
推荐答案
试试这个:
//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];
这篇关于Xcode Obj - C - 从Alert Box IOS8检索用户输入的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文