objective-c – 将带有NSTextAttachment的NSAttributedString保存到文件中.如何?

objective-c – 将带有NSTextAttachment的NSAttributedString保存到文件中.如何?,第1张

概述我有一个NSTextView,它可能包含富文本或富文本,图像为NSTextAttachment.有我如何添加附件: NSImage *image = [NSImage imageNamed:@"image"];NSTextAttachmentCell *attachmentCell =[[NSTextAttachmentCell alloc] initImageCell:image];NST 我有一个NSTextVIEw,它可能包含富文本或富文本,图像为NSTextAttachment.有我如何添加附件:

NSImage *image = [NSImage imagenamed:@"image"];NSTextAttachmentCell *attachmentCell =[[NSTextAttachmentCell alloc] initimageCell:image];NSTextAttachment *attachment =[[NSTextAttachment alloc] init];[attachment setAttachmentCell: attachmentCell ];NSAttributedString *attributedString =[NSAttributedString  attributedStringWithAttachment: attachment];[[aTextVIEw textStorage] beginEditing];if ([aTextVIEw shouldChangeTextInRange:NSMakeRange([aTextVIEw selectedRange].location,0) replacementString:@""]) {    [[aTextVIEw textStorage] insertAttributedString:attributedString atIndex:[aTextVIEw selectedRange].location];    [aTextVIEw dIDChangeText];}[[aTextVIEw textStorage] endEditing];

我的-fileWrapperOfType:错误:方法:

- (NSfileWrapper *)fileWrapperOfType:(Nsstring *)typename error:(NSError *__autoreleasing *)outError{    NSRange documentRange = NSMakeRange(0,[[[WindowController aTextVIEw] textStorage] length]);    NSTextStorage *text = [[WindowController aTextVIEw] textStorage];    NSfileWrapper *resultWrapper = nil;    if ([typename compare:@"public.rtf"] == NSOrderedSame) {        resultWrapper = [[NSfileWrapper alloc] initRegularfileWithContents:[text RTFFromrange:documentRange documentAttributes:[NSDictionary dictionaryWithObjectsAndKeys:NSRTFTextdocumentType,NSdocumentTypedocumentAttribute,nil]]];    }    else if ([typename compare:@"com.apple.rtfd"] == NSOrderedSame) {        resultWrapper = [text RTFDfileWrapperFromrange:documentRange documentAttributes:[NSDictionary dictionaryWithObjectsAndKeys:NSRTFDTextdocumentType,nil]];    }    return resultWrapper;}

但是当我保存RTFD时,所有附件都会丢失.请帮忙.我错过了什么?

解决方法 我找到了一个可接受的解决方案,它在这里描述: Cocoa: custom attachment in a text view 总结

以上是内存溢出为你收集整理的objective-c – 将带有NSTextAttachment的NSAttributedString保存到文件中.如何?全部内容,希望文章能够帮你解决objective-c – 将带有NSTextAttachment的NSAttributedString保存到文件中.如何?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1001052.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存