2010-07-02 6 views
4

이전 응용 프로그램 실행에서 저장 한 NSData 인스턴스가 있습니다. 이 데이터를 사용하여 NSTextView의 텍스트를 설정하려고합니다. 그것은 RTF이고 나는 이것을하는 방법을 이해할 수 없다. 어떤 아이디어 나 제안? Interface Builder가 아닌 코드로 작업해야합니다.NSData를 사용하여 NSTextView에 텍스트 설정

감사

답변

9
//First convert a NSData object to a NSString object. 

NSData *aData; 
//assign aData to what you want it to. 
NSAttributedString *aStr; 
aStr = [[[NSAttributedString alloc] initWithRTF:aData documentAttributes:NULL] autorelease]; 
//then set the textView to that value. 

[[yourTextView textStorage] setAttributedString:aStr]; 
+0

RTF를 해석하고 싶다고 가정합니다. – JWWalker

+0

좋아 답 : 응답에 대한 –

+3

감사를 편집 할 수 있지만 나는 텍스트 뷰의 기인 문자열을 설정하려고 할 때이 오류를 *** 얻을 - [NSBigMutableString replaceCharactersInRange : withString :] : 무기 호 인수 어떤 아이디어? – bob

0

당신은 RTF 데이터를 사용하여 NSAttributedString은 초기화 할 수 있으며를 NSTextView 소유 NSTextStorage는 NSMutableAttributedString에서 유래. 나는 당신이 그것들을 함께 모을 수 있다고 생각합니다.

2
 
NSData *myData; // RTF data 
NSAttributedString *myString = [[NSAttributedString alloc] initWithRTFD:myData documentAttributes:NULL]; 

[[yourTextView textStorage] setAttributedString:myString]; 

thyrgle 가까이이지만, NSAttributedString은 당신이 텍스트 필드 또는 UIView의에 카테고리를 구현

initWithRTFD: documentAttributes:
대신

0

initWithRTF: documentAttributes:
의 체크? (당신이 범주를 구현하는 기반 UI에있는) 경우를 사용하여 초기화 할 필요가 그렇다면 해당 범주를 제거하고 다시 확인하십시오.

관련 문제