Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

matthew858

macrumors member
Original poster
Apr 15, 2008
97
0
Sydney, Australia
I have 2 UITextFields inside a UIAlertView like so:
Code:
	UIAlertView *firstTimeWelcome = [[UIAlertView alloc] 
					 initWithTitle: @"Welcome!" 
					 message:@"Please enter your details:" 
					 delegate:self 
					 cancelButtonTitle:nil 
					 otherButtonTitles:@"Continue", nil]; 
	[firstTimeWelcome addTextFieldWithValue:@""label:@"Username"]; 
	[firstTimeWelcome addTextFieldWithValue:@""label:@"Password"]; 
	

        // Name field 
	UITextField *tf = [firstTimeWelcome textFieldAtIndex:0]; 
	tf.clearButtonMode = UITextFieldViewModeWhileEditing; 
	tf.keyboardType = UIKeyboardTypeAlphabet; 
	tf.keyboardAppearance = UIKeyboardAppearanceAlert; 
	tf.autocapitalizationType = UITextAutocapitalizationTypeNone; 
	tf.autocorrectionType = UITextAutocorrectionTypeNo; 
	username = tf.text;


	//Password Field
	tf = [firstTimeWelcome textFieldAtIndex:1]; 
	tf.clearButtonMode = UITextFieldViewModeWhileEditing; 
	tf.keyboardType = UIKeyboardTypeAlphabet; 
	tf.secureTextEntry = YES;
	tf.keyboardAppearance = UIKeyboardAppearanceAlert; 
	tf.autocapitalizationType = UITextAutocapitalizationTypeNone; 
	tf.autocorrectionType = UITextAutocorrectionTypeNo; 
	password = tf.text;
	[firstTimeWelcome show]; 
	[firstTimeWelcome release];

The issue that I am having is that I can't seem to get password or username (both NSStrings) to store the values of the text fields. What am I doing wrong?
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
You're trying to access the values BEFORE you've shown the alert. You need to do it after the alert has been dismissed (this means in another method in the alertViews delegate - I can't remember which method it is that gets called - it's in the docs).
 

matthew858

macrumors member
Original poster
Apr 15, 2008
97
0
Sydney, Australia
Can:
Code:
- (void)alertView:(UIAlertView *)actionSheet ClickedButtonAtIndex:(NSInteger)buttonIndex {

be used to grab the contents of the text boxes, or is there another method? I am currently using the above code to link the button press to another action.
 

matthew858

macrumors member
Original poster
Apr 15, 2008
97
0
Sydney, Australia
That's the only alert view that I have in my app. So, can I use:

Code:
username = tf.text;
password = tf.text;

within the code I posted in my 2nd reply above and have it work?

Edit: What I had to do was declare the text view in the delegate, but it is still not passing the value of the text field. Any help?
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
How are you accessing the textfields in the clickedButton method ?

Incidently I noticed you had the message as having

ClickedButtonAtIndex

it should be

clickedButtonAtIndex

If this is wrong in your code the method won't get called.
 

matthew858

macrumors member
Original poster
Apr 15, 2008
97
0
Sydney, Australia
The code used is the code in the very first post plus:
Code:
- (void)alertView:(UIAlertView *)firstTimeWelcome clickedButtonAtIndex:(NSInteger)buttonIndex {
	if (buttonIndex == 0) {
		password = tf.text;
		[self sendToServer];
	}
}

sendToServer is a custom function that is to do with push notification, and unrelated.
 

caveman_uk

Guest
Feb 17, 2003
2,390
1
Hitchin, Herts, UK
Is tf now an instance variable? Previously it was only in scope in the method where you created the alertview.

Can you put an NSLog debug line in the clickedButton...method to see if it's actually being called?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.