Reputation: 209
I created a UI by parsing XML (I haven't used a xib file). That is, I created two text fields and one button. Now I want to get both textfield values when the button is clicked. Can anyone suggest how to do this?
Upvotes: 1
Views: 981
Reputation: 11
You can access the text of a UITextField
using
NSString *textFieldValue = myTextField.text;
or use
NSString *textFieldValue = [myTextField text];
Upvotes: 0
Reputation: 798
You have to declare UITextField other wise you cant access the textfields
Upvotes: 0
Reputation: 16240
Make sure your button has this:
[button addTarget:self action:@selector(getTextValue:)
forControlEvents:UIControlEventTouchUpInside];
Then, make this method (or whatever is in your @selector):
-(void)getTextValue:(id)sender {
NSString *one = yourtextfield.text;
NSString *two = yourtextfield2.text;
}
Upvotes: 1
Reputation: 31730
Use the text property of UITextField
, like below
NSString* myFirstValue = [myFirstTextField.text retain];
NSString* mySecondValue = [mySecondTextField.text retain];
after using both value don't forget to release them
[myFirstValue release];
[mySecondValue release];
Upvotes: 0
Reputation: 11145
if you have created textfield by code and you want to get text of textfield in button action then you can declare textfield in .h file and in your action call
[textfield text];
Upvotes: 0