4

アプリケーションの前回の実行から保存した NSData のインスタンスがあります。このデータを使用して NSTextView のテキストを設定したいと考えています。それはRTFであり、これを行う方法がわかりません。アイデアや提案はありますか?これは、Interface Builder ではなく、コードで行う必要があります。

ありがとう

4

4 に答える 4

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];
于 2010-07-02T05:58:10.473 に答える
2
NSData *myData; // RTF データ
NSAttributedString *myString = [[NSAttributedString alloc] initWithRTFD:myData documentAttributes:NULL];

[[yourTextView textStorage] setAttributedString:myString];

thyrgle は近いですが、NSAttributedString を使用して初期化する必要があります

initWithRTFD: documentAttributes:
それ以外の
initWithRTF: documentAttributes:

于 2010-07-04T05:06:15.617 に答える
0

RTF データを使用して NSAttributedString を初期化でき、NSTextView が所有する NSTextStorage は NSMutableAttributedString から派生します。そこからパーツを組み立てていくことができると思います。

于 2010-07-02T05:58:11.317 に答える
0

テキストフィールドまたは uiview にカテゴリを実装していることを確認しますか? (カテゴリを実装した組み込みの ui のいずれか) はいの場合は、そのカテゴリを削除して再度確認します。

于 2017-06-27T09:43:53.717 に答える