代码在iphone webView中打开.docx

时间:2012-07-28 09:31:43

标签: iphone ios ipad uiwebview

我是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'

考虑到我复制了文件" Arabic literature.docx"在支持文件中。 我怎样才能解决这个异常?

1 个答案:

答案 0 :(得分:0)

好吧,为什么不使用这样的东西:

 NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];

抱歉评论不起作用,所以不得不给出答案。