OGeek|极客世界-中国程序员成长平台

标题: ios - CSS 和 JS 文件未在 uiwebview 中加载 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 09:32
标题: ios - CSS 和 JS 文件未在 uiwebview 中加载

在我的应用程序中,一个包含在文件夹中的网站。我尝试使用以下代码在 webview 中加载它:

self.wView.dataDetectorTypes = UIDataDetectorTypeLink;
NSString *htmlFile = [[NSBundle mainBundle] pathForResource"index" ofType"html" inDirectory:NO];
    NSLog(@"%@",htmlFile);
    //NSData *pathData = [NSData dataWithContentsOfFile:htmlFile];
    //NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
    NSURL *url = [NSURL URLWithString:[htmlFile lastPathComponent] relativeToURL:[NSURL fileURLWithPath:[htmlFile stringByDeletingLastPathComponent] isDirectory:YES]];

    //(void)[NSURLConnection connectionWithRequest:req delegate:self];
    [self.wView loadRequest:[NSURLRequest requestWithURL:url]] ;

我在 nslog 中获取文件路径。 但是在我的 webview 中,css 和 js 文件没有加载。

请帮助我。



Best Answer-推荐答案


这个问题的简单解决方案

在将网站文件夹复制到 XCode 时,只需选择选项为任何添加的文件夹创建文件夹引用

关于ios - CSS 和 JS 文件未在 uiwebview 中加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15331608/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4