user2818570
user2818570

Reputation: 23

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.

- (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. "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? thanks!

Upvotes: 0

Views: 50

Answers (2)

Rok Jarc
Rok Jarc

Reputation: 18865

If your text fields are added to the view in XIB then make sure you have your IBOutlets connected to your textfields. 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];

...

Upvotes: 0

Greg
Greg

Reputation: 25459

You can create string with your uitextfields like:

- (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.

Upvotes: 1

Related Questions