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
.
精彩评论