2012-06-20 9 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; 
    } 
} 
관련 문제