RTF中的NSAttributedString仅适用于iOS 8,不适用于iOS 7
我正在尝试使用以下代码在UITextView中加载RTF文件:RTF中的NSAttributedString仅适用于iOS 8,不适用于iOS 7,ios,uitextview,rtf,nsattributedstring,Ios,Uitextview,Rtf,Nsattributedstring,我正在尝试使用以下代码在UITextView中加载RTF文件: NSURL * filePath = [[NSBundle mainBundle] URLForResource:_fileName withExtension:@"rtf"]; NSAttributedString *stringWithRTFAttributes = [[NSAttributedString alloc] initWithFileURL:filePath options:@{NSDocumentTypeDocu
NSURL * filePath = [[NSBundle mainBundle] URLForResource:_fileName withExtension:@"rtf"];
NSAttributedString *stringWithRTFAttributes = [[NSAttributedString alloc] initWithFileURL:filePath options:@{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType} documentAttributes:nil error:nil];
myTextView.attributedText = stringWithRTFAttributes;
在iOS 8上它工作得很好,但在iOS 7上它不工作,它只显示没有属性的文本。我解决了这个问题,将RTF文件保存为HTML(使用TextEdit),并将代码更改为
NSURL * filePath = [[NSBundle mainBundle] URLForResource:_fileName withExtension:@"html"];
NSAttributedString *stringWithHTMLAttributes = [[NSAttributedString alloc] initWithFileURL:filePath options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType} documentAttributes:nil error:nil];
myTextView.attributedText = stringWithHTMLAttributes;
有人能帮我吗?它和iOS8.0一起工作吗?我得到了“libc++abi.dylib:以std::out_of_range:vector类型的未捕获异常终止”,而它确实适用于以后的8.x版本!不幸的是,我没有iOS 8.0设备,但部署目标设置为7.0。我想,这是一个运行时错误?也许有人有iOS 8.0设备,可以测试它??