【发布时间】:2012-07-26 20:14:03
【问题描述】:
我是 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'
请考虑我在支持文件中复制了文件“Arabicliterature.docx”。 我该如何解决这个异常??
【问题讨论】:
-
您是否在 NSData 中得到了一些东西,或者您的应用程序在此之前就崩溃了?您的文档是保存在您的应用文件夹中还是其他地方?
-
是的,我在应用程序文件夹中看到了文档
-
您是否在 NSdata 中获得了任何价值?
-
由于未捕获的异常 'NSInvalidArgumentException' 导致应用程序终止,原因:'*** -[NSURL initFileURLWithPath:]: nil string parameter'
-
是的,这个错误意味着你的文件在包路径中不存在..首先将它复制到那里然后找到这个“NSString *urlAddress”