2011-09-27 4 views
0

는 "성"나는 이러한 작업을 구현하려는은 UITextView (아이폰)에서이 작업을 수행하는 방법에 내 텍스트 뷰에서

.. 기본값이

1)이 표시되어야입니다 필드가 여전히 만약 내가 내 편집을 완료입니다 "이름"먼저
2) 나는 그것이
3 전무가되었다한다 편집을 시작) 후 다시 "이름"

수로 표시한다 NIL 누구든지 이걸 도와 줘?

// *이것은 내가 지금 뭐하는 거지 지금** //

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range 
    replacementText:(NSString *)text 
     {  
if ([email protected]"") { 
    [email protected]"First Name(Required)"; 
    } 
// Any new character added is passed in as the "text" parameter 
if ([text isEqualToString:@"\n"]) { 
    // Be sure to test for equality using the "isEqualToString" message 

    [textView resignFirstResponder]; 

    // Return FALSE so that the final '\n' character doesn't get added 
    return FALSE; 
} 
// For any other character return TRUE so that the text gets added to the view 
return TRUE; 
    return TRUE; 
} 


- (BOOL)textViewShouldBeginEditing:(UITextView *)textView { 
NSLog(@"textViewShouldBeginEditing"); 
textView.scrollEnabled=NO; 

if (textView == first_name) { 
    first_name.text=nil; 
} 


return YES; 

}

+0

UITextField를 의미합니까? placeHolder라는 속성이 있습니다. –

+0

아니요 textView .... –

+0

esqew가 아래에 언급했듯이 대리자 메서드를 사용하십시오 textViewDidStart/End-Editing –

답변

0

텍스트보기 상단에 UILabel을 원하는 텍스트로 겹치고 userInteractionEnabled를 NO로 설정하고 텍스트 필드 delegate 메소드 shouldBeginEditing에서 YES를 반환하기 전에 UILabel을 숨기고 shouldFinishEditing에서 다시 숨길 필요가 있습니다.

관련 문제