Dr.*_*eon 3 cocoa rtf objective-c nstextview nsattributedstring
好的,我们在这里:
NSTextViewNSMutableAttributedString满足通过使用Rob的代码(将自定义属性保存在NSAttributedString中),我已经取得了一些进展(我正在设法将数据写入磁盘),但是我无法恢复它(= NSKeyedUnarchiverreturn nil)。
编码方式:
// where MAS --> NSMutableAttributedString
NSData* stringData = [NSKeyedArchiver archivedDataWithRootObject:MAS];
Run Code Online (Sandbox Code Playgroud)
解码:
NSMutableAttributedString* mas = (NSMutableAttributedString*)[NSKeyedUnarchiver unarchiveObjectWithData:dat];
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?任何可能的解决方法(即使不能使用NSCoder,我都怀疑它可以与RTF一起使用...)!
这就是解决方法。
NSAttributedString-> NSData:
NSData* j = [(NSMutableAttributedString*)MAS RTFDFromRange:NSMakeRange(0,[[MAS string] length])
documentAttributes:nil];
Run Code Online (Sandbox Code Playgroud)
NSData -> NSAttributedString
NSMutableAttributedString* mas = [[NSMutableAttributedString alloc] initWithRTFD:dat
documentAttributes:nil];
Run Code Online (Sandbox Code Playgroud)
就那么简单。
| 归档时间: |
|
| 查看次数: |
843 次 |
| 最近记录: |