-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *enteredName = [[alertView textFieldAtIndex:0]text];
NSLog(@"name===>%@",enteredName);
}
如何在viewDidLoad或任何其他函数中访问“enteredName”值。我使用了alert.alertViewStyle = UIAlertViewStylePlainTextInput;
答案 0 :(得分:3)
message.alertViewStyle = UIAlertViewStylePlainTextInput;
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
if([title isEqualToString:@"Login"])
{
UITextField *username = [alertView textFieldAtIndex:0];
UITextField *password = [alertView textFieldAtIndex:1];
NSLog(@"Username: %@\nPassword: %@", username.text, password.text);
}
}