2013-12-19 2 views
0

텍스트 상자를 투명 또는 흰색으로 렌더링하게하는 UIAlertView/SubView 문제를 최근에 업데이트 한 iOS 앱이 있습니다 (또는 전혀 렌더링되지 않거나 어느 것이 확실하지 않음) . 어쨌든, Obj-C를 처음 접했을 때 상대적으로 간단한 질문이지만, 응용 프로그램의 다른 호출에서 새 텍스트 상자의 가치를 얻으려면 어떻게해야합니까? 그것은 UITextField에 저장하는 데 사용하고 하위 뷰로 UIAlertView에 추가iOS 앱의 UIAlertView 텍스트 상자에서 값 가져 오기

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Password" 
         message:@"Enter your Password\n\n\n" 
         delegate:self 
         cancelButtonTitle:@"Cancel" 
         otherButtonTitles:@"Login", nil]; 
alert.frame = CGRectMake(0, 30, 300, 260); 

: 여기

내 UIAlertView입니다이 모든 이제 주석

psswdField = [[UITextField alloc] initWithFrame:CGRectMake(32.0, 65.0, 220.0, 25.0)]; 
    psswdField.placeholder = @"Password"; 
    psswdField.secureTextEntry = YES; 
    psswdField.delegate = self; 
    psswdField.tag = 1; 
    [psswdField becomeFirstResponder]; 
    [alert addSubview:psswdField]; 
    [alert show]; 
    [alert release]; 

하고, 대신 다음과 같이 다시 써야합니다.

alert.alertViewStyle = UIAlertViewStyleSecureTextInput; 

값을 검색하는 방법은 다음과 같습니다.

[psswdField resignFirstResponder]; 
[psswdField removeFromSuperview]; 

activBkgrndView.hidden = NO; 
[activInd startAnimating]; 
[psswdField resignFirstResponder]; 
[self performSelectorInBackground:@selector(loadData:) withObject:psswdField.text]; 

이제이 텍스트 상자의 값을 loadData로 보내는 방법에 대해 혼란스러워합니다.

답변

5

경고보기에 자신의 텍스트 필드를 추가하고 싶지 않습니다. UIAlertView에 하위 뷰를 직접 추가하지 않아도됩니다. UIAlertView의 alertViewStyle 속성은 UIAlertViewStyleSecureTextInput으로 설정하여 텍스트 필드를 추가합니다. 이 같은 라인을 설정합니다 그래서 :

alert.alertViewStyle = UIAlertViewStyleSecureTextInput; 

그런 다음 당신은 당신이 당신의 UIAlertView의 대리인으로 설정하는 당신이 클래스에 추가해야합니다 대리자 방법 - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex을 사용하여이 텍스트 필드의 값을 검색합니다 . 위임 메서드의 구현 예는 다음과 같습니다.

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex 
{ 
    // Make sure the button they clicked wasn't Cancel 
    if (buttonIndex == alertView.firstOtherButtonIndex) { 
     UITextField *textField = [alertView textFieldAtIndex:0]; 

     NSLog(@"%@", textField.text); 
    } 
} 
+0

맞습니다. 내 질문에서 볼 수 있듯이 나는 이미 첫 번째 부분을하고있다. 도움이 필요한 곳은 실제로 텍스트 필드를 검색하는 방법의 샘플입니다. 다시 말하지만, 저는 iOS에 익숙하지 않습니다. obj-c보다 C# 사용자가 더 많습니다. 나는 그 안에서 돌아 다닐 수는 있지만 아직 익숙하지는 않다. – optionsix

+0

정말 도움이 필요한 것 : alert.alertViewStyle = UIAlertViewStyleSecureTextInput 부분이 입력 용 텍스트 상자를 생성합니다. didDismissWithButtonIndex 메서드는 버튼을 누르면 해당 텍스트 상자로 작업을 수행합니다. 어떻게하면 흐릿 해지는 지, 대리자 메서드에서 해당 텍스트 상자의 데이터를 가져올 수 있습니까? – optionsix

+0

방금 ​​대화 상자를 닫을 때 콘솔에 텍스트 필드의 값을 출력하는 대리자 메서드의 구현 예제를 추가했습니다. 그래서 당신은 텍스트 필드에서 어떻게 보는지 알 수 있습니다. – Gavin

관련 문제