I have got an alertview which has a text field
UIAlertView* dialog = [[UIAlertView alloc] init];
dialog.tag = 5;
[dialog setDelegate:self];
dialog.delegate = self;
[dialog setTitle:@"Please set the quantity:"];
[dialog setMessage:@"Quantity"];
[dialog addButtonWithTitle:@"Cancel"];
[dialog addButtonWithTitle:@"SET"];
UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
[nameField setBackgroundColor:[UIColor whiteColor]];
//nameField.keyboardType = UIKeyboardTypeDecimalPad;
NSString *str = nameField.text;
NSLog(@"%@",str);
[dialog addSubview:nameField];
[dialog show];
[dialog release];
[nameField release];
I’m trying to store the values of the textfield after the alertviews dismissal as
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag ==5) {
if(buttonIndex == 1)
{
UITextField* textField = (UITextField*)[alertView.subviews objectAtIndex:2];
NSLog(@"%@",textField.text);
}
}
}
But the text field is returning null, what is the value that im supposed to give or objectatindex?
Thanks.
Try this