iOS Objective C: Display RTF document

爷,独闯天下 提交于 2020-01-01 08:49:42

问题


I want to show a RTF document in a view. This document will be developed in Microsoft Word and will contains images.

What is the best way to do this using standard routines provided?

I would really like sample code to load a RTF document from the bundle. Kind Regards, Jason


回答1:


UIWebView opens .rtf documents. Try something like

NSURL *rtfUrl = [[NSBundle mainBundle] URLForResource:@"MyFileName" withExtension:@"rtf"];
NSURLRequest *request = [NSURLRequest requestWithURL:rtfUrl];
[_webview loadRequest:request];

See the documentation for UIWebView file types.




回答2:


If you need to do this in Swift instead of Obective-C here's a Swift equivalent of @pmf's answer as a function you can call.

func loadRTFDocument() {
    let urlPath =  NSBundle.mainBundle().pathForResource("TermsOfUse", ofType: "rtf")
    let url = NSURL.fileURLWithPath(urlPath!)
    let request = NSURLRequest.init(URL: url)
    self.webView.loadRequest(request)
}


来源:https://stackoverflow.com/questions/9501240/ios-objective-c-display-rtf-document

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!