简体   繁体   English

根据文本字段中的键入文本显示消息

[英]Show message depending on typed text in textfield

Good day! 美好的一天! i have this code for UIAlertView that when you press the button it will show a message what ever you typed. 我有UIAlertView的这段代码,当您按下按钮时,它将显示一条消息,无论您键入什么。

- (IBAction)sellClick:(id)sender {

        UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Confirmation"
                                                       message: @"Message"
                                                      delegate: self
                                             cancelButtonTitle:@"Cancel"
                                             otherButtonTitles:@"OK",nil];


        [alert show];
        [alert release];
}

now what i want is what if i have 3 or more UITextfields and when i press the button i want to show all the typed text in UItextfield to UIAlertView for example in my 1st text field i typed. 现在我想要的是如果我有3个或更多UITextfields,当我按下按钮时,我想将UItextfield中所有键入的文本显示给UIAlertView,例如在我键入的第一个文本字段中。 "WANT" and 2nd is "LARRY" and 3rd is "PLAY" when i press the button it shows the alert message, "I WANT LARRY to PLAY" , how can i make it like that? 当我按下按钮时,“ WANT”和第2个是“ LARRY”,第3个是“ PLAY”,它显示警报消息“ I WANT LARRY to PLAY”,我该怎么做? thanks! 谢谢!

You can create string with your uitextfields like: 您可以使用uitextfields创建字符串,例如:

- (IBAction)sellClick:(id)sender {

        NSString *message = [NSString stringWithFormat:@"I %@ %@ to %@", textField1.text, textField1.text, textField1.text]
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Confirmation"
                                                       message: message
                                                      delegate: self
                                             cancelButtonTitle:@"Cancel"
                                             otherButtonTitles:@"OK",nil];


        [alert show];
        [alert release];
}

Hope this help. 希望对您有所帮助。

If your text fields are added to the view in XIB then make sure you have your IBOutlets connected to your textfields. 如果将文本字段添加到XIB的视图中,请确保已将IBOutlets连接到文本字段。 Such as: 如:

@property (weak) IBOutlet UITextField* textField1;
@property (weak) IBOutlet UITextField* textField2;
@property (weak) IBOutlet UITextField* textField3;

Then you could simply compose a message: 然后,您可以简单地编写一条消息:

NSString *message = [NSString stringWithFormat:@"I %@ %@ to %@",self.textField1.text,self.textField2.text,self.textField3.text];

UIAlertView *alert = [[UIAlertView alloc]initWithTitle: @"Confirmation"
                                                       message: message
                                                      delegate: self
                                             cancelButtonTitle:@"Cancel"
                                             otherButtonTitles:@"OK",nil];

...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM