2012-11-23 2 views
2

UIAlertView를 표시하여 사용자에게 일부 텍스트를 변경하도록 요청해야하지만 대부분의 경우 사용자는 다음을 원합니다. a) 그대로 텍스트를 그대로 두거나 b) 전체 텍스트를 바꿉니다. 매우 드물 긴하지만 텍스트를 추가하거나 수정하여 텍스트를 변경하려고합니다. 경고가 표시 될 때이 아이폰에서 잘 작동UIAlertView 내부의 UITextField : 텍스트를 선택하는 방법?

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Name for your item" 
                message:nil 
                delegate:self 
              cancelButtonTitle:@"Cancel" 
              otherButtonTitles:@"Accept", nil]; 
alertView.alertViewStyle = UIAlertViewStylePlainTextInput; 
UITextField *textField = [alertView textFieldAtIndex:0]; 
textField.text = @"Some random text"; 
[alertView show]; 

UITextRange *textRange = [textField textRangeFromPosition:textField.beginningOfDocument 
               toPosition:textField.endOfDocument]; 
[textField setSelectedTextRange:textRange]; 

, 텍스트를 선택하고 내가 원하는만큼 그것을 작동 :

그래서,이 목적을 위해 나는 다음과 같은 코드 조각으로 왔어요 기대하지만 iPad에서는 텍스트가 전혀 선택되지 않습니다.

내가 잘못하고있는 것은 iOS의 버그입니까, 아니면이 동작이 내가 찾지 못한 문서일까요?

+0

텍스트 범위 변수를 기록하여 0 또는 NULL인지 확인합니다. – CodaFi

+0

@Opsi iOS 5 및 iOS 6 모두에서 iPad 시뮬레이터에서 코드가 작동합니다. 테스트 환경은 무엇입니까? –

+0

그건 빠르다;) 사실, 그 범위는 iPad에서 끝나지 만 iPhone에서는 그렇지 않기 때문에 버그를 채울 시간이다 ... 감사합니다! – opsidao

답변

0
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"name" message:@"" delegate:self 
              cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil]; 

alertViewt.alertViewStyle = UIAlertViewStylePlainTextInput; 
UITextField *textField = [Renamealert textFieldAtIndex:0]; 
[email protected]"XYZZZ "; 
[alertView show]; 

UITextRange *textRange = [textField textRangeFromPosition:textField.beginningOfDocument 
               toPosition:textField.endOfDocument]; 
[textField setSelectedTextRange:textRange]; 
+0

이 답변을 원래 질문에 추가하는 내용이 표시되지 않습니다 ... 조금 자세히 설명해 주시겠습니까? – opsidao

관련 문제