代码之家  ›  专栏  ›  技术社区  ›  Knodel

uiWebView不显示我希望它显示的内容

  •  0
  • Knodel  · 技术社区  · 16 年前

    在我的应用程序中,我有一个uiwebview,它可以加载不同的rtf文件。我使用此函数加载这些文件:

    - (void)loadFile:(NSString*)file
    {
    NSString* resourcePath = [[NSBundle mainBundle] resourcePath];
    NSString* sourceFilePath = [resourcePath stringByAppendingPathComponent:file];
    NSURL* url = [NSURL fileURLWithPath:sourceFilePath isDirectory:NO];
    NSURLRequest* request = [NSURLRequest requestWithURL:url];
    [webview loadRequest:request];
    }
    

    uiWebView不显示任何内容。当我进入调试器时,文件字符串值是我需要的,但是resourcepath和sourcefilepath值是“nil”。我做错什么了?

    事先谢谢!

    1 回复  |  直到 16 年前
        1
  •  1
  •   kennytm    16 年前

    试用使用 -pathForResource:ofType: 相反。

    NSString* sourceFilePath = [[NSBundle mainBundle] pathForResource:file ofType:nil];