开发者

NSTextView "data" binding problem

I have a NSTextView textView bind its "data" to "content" property

textView's rich text support is turned off.

When textView's content changed, I have its "data" is nil, though its string and rtf is available.

- (NSData*)content ;

- (void)setContent:(NSData *)data;
{
    NSString* s = [textView string];
    NSData* rtf = [textView RTFDFromRange:NSMakeRange(0, [s length])];
// data == nil
// s != nil
// rtf != nil
}

"data" is not nil if I enable 开发者_如何转开发textView's rich text support.

Why is "data" nil ?


From the docs:

data

An NSData instance containing the formatted text of the NSTextView.

The NSData contains either the RTF or RTFD representation of the NSTextView contents, depending on the configuration of the NSTextView.

This binding is only available when the NSTextView is configured to allow multiple fonts. (emphasis added)

In other words, you must turn on Rich Text support to use this binding. If you just want to bind a plain string, use the value binding or for an attributed string use the attributedString binding instead of data.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜