我有一个带有文本字段的警报视图
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];
我试图在 alertviews 解雇后将文本字段的值存储为
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if (alertView.tag ==5) {
if(buttonIndex == 1)
{
UITextField* textField = (UITextField*)[alertView.subviews objectAtIndex:2];
NSLog(@"%@",textField.text);
}
}
}
但是文本字段返回 null,我应该给出的值或 objectatindex 是什么?
谢谢。