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保存到文件中.如何?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)