为什么UIWebView本地文件会出现NSException错误?

时间:2011-11-27 20:19:53

标签: iphone objective-c ios xcode uiwebview

  

可能重复:
  Problem calling a Local HTML File from XCode

我在已经存在的UIWebView中使用以下代码将本地文件调用到UIWebView中:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"iDHSB_iPod/Calendar" ofType:@"html"]isDirectory:NO]]];

然而,当按下按钮执行此功能时 - 我收到此错误:

2011-11-27 20:17:37.667 iDHSB[806:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** 
-[NSURL initFileURLWithPath:isDirectory:]: nil string parameter'
*** First throw call stack:
(0x37c598bf 0x3173f1e5 0x37c597b9 0x37c597db 0x31b014ff 0x31b01493 0x4b609 0x37bb3435 0x3502c9eb 0x3502c9a7 0x3502c985 
0x3502c6f5 0x3502d02d 0x3502b50f 0x3502af01 0x350114ed 0x35010d2d 0x3772edf3 0x37c2d553 0x37c2d4f5 0x37c2c343 0x37baf4dd 
0x37baf3a5 0x3772dfcd 0x3503f743 0x2e8b 0x28d4)
terminate called throwing an exception[Switching to process 7171 thread 0x1c03]
(gdb) 

2 个答案:

答案 0 :(得分:3)

根据错误判断,[[NSBundle mainBundle] pathForResource:@"iDHSB_iPod/Calendar" ofType:@"html"]会返回nil

答案 1 :(得分:1)

您不能使用本地路径作为pathForResource:ofType方法的参数;它只接受资源名称。