2012-06-20 86 views
2

我想要显示消息框包含标签和文本框,并确定按钮和取消按钮,当用户按下主要故事板中的按钮并在用户按ok后在文本框中获取字符串IOS?如何在消息框中显示文本框objective-c

我知道如何显示错误消息或类似的东西,但我不知道如何显示消息框?

回答

5
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Save" 
                 message:@"Enter File Name" 
                 delegate:self 
               cancelButtonTitle:@"Cancel" 
               otherButtonTitles:@"OK", nil]; 

    alertView.alertViewStyle = UIAlertViewStylePlainTextInput; 

    [alertView show]; 



- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    NSLog(@"Alert View dismissed with button at index %d",buttonIndex); 

    switch (alertView.alertViewStyle) 
    { 
     case UIAlertViewStylePlainTextInput: 
     { 
      UITextField *textField = [alertView textFieldAtIndex:0]; 
      NSLog(@"Plain text input: %@",textField.text); 
     } 
      break; 

     case UIAlertViewStyleSecureTextInput: 
     { 
      UITextField *textField = [alertView textFieldAtIndex:0]; 
      NSLog(@"Secure text input: %@",textField.text); 
     } 
      break; 

     case UIAlertViewStyleLoginAndPasswordInput: 
     { 
      UITextField *loginField = [alertView textFieldAtIndex:0]; 
      NSLog(@"Login input: %@",loginField.text); 

      UITextField *passwordField = [alertView textFieldAtIndex:1]; 
      NSLog(@"Password input: %@",passwordField.text); 
     } 
      break; 

     default: 
      break; 
    } 
}