从alertView clickedbuttonAtIndex方法访问值

时间:2012-09-17 08:23:34

标签: objective-c ios xcode uialertview

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
        NSString *enteredName = [[alertView textFieldAtIndex:0]text];
        NSLog(@"name===>%@",enteredName);
}

如何在viewDidLoad或任何其他函数中访问“enteredName”值。我使用了alert.alertViewStyle = UIAlertViewStylePlainTextInput;

1 个答案:

答案 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);

  }
}