我是 iPhone 新手,我正在尝试在 UIwebView 中打开 .docx 文件,我编写了以下代码
NSString *urlAddress = [[NSBundle mainBundle] pathForResource:@"Arabic literature"
ofType:@"docx"];
NSURL *url = [NSURL fileURLWithPath:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
NSData *data = [NSData dataWithContentsOfFile:urlAddress];
//[_webView loadRequest:requestObj];
[_webView loadData:data MIMEType:@"application/vnd.ms-word" textEncodingName:@"UTF-8" baseURL:nil];
但它给了我以下例外:
DiskImageCache: Could not resolve the absolute path of the old directory.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSURL initFileURLWithPath:]: nil string parameter'
考虑到我在支持文件中复制了文件“阿拉伯文学.docx”。
我该如何解决这个异常?
好吧,你为什么不使用这样的东西:
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
抱歉,评论不起作用,所以不得不将其作为答案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)