将html加载到Uiwebview IOS时不加载JS和CSS文件?

时间:2016-10-19 09:06:28

标签: ios iphone ipad

我有一个应用程序,我正在下载html文件,并将js和css文件放入应用程序文档目录。然后当我将html添加到UIwebview时,CSS文件没有加载。我这样做< / p>

`  NSString *docsDir;
    NSArray *dirPaths;

    dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    docsDir = [dirPaths objectAtIndex:0];



    NSArray *ipaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *idocumentsDir = ([ipaths count] > 0) ? [ipaths objectAtIndex:0] : nil;
    NSString *str=[NSString stringWithFormat:@"%@",[dictionary valueForKey:@"htmlfilename"]];
    NSString *idataPath = [idocumentsDir stringByAppendingPathComponent:str];
    NSLog(@"idataPath:%@",idataPath);

    //Create folder here
    if ([[NSFileManager defaultManager] fileExistsAtPath:idataPath])
    {





        NSError *err;
        NSString *html = [NSString stringWithContentsOfFile:idataPath encoding:NSUTF8StringEncoding error:&err];
        html = [html stringByReplacingOccurrencesOfString:@"../css/style-ios.css" withString:@"./style-ios.css"];
        html = [html stringByReplacingOccurrencesOfString:@"../.././style-ios.css" withString:@"./style-ios.css"];
        html = [html stringByReplacingOccurrencesOfString:@"../../../style-ios.css" withString:@"./style-ios.css"];
        html = [html stringByReplacingOccurrencesOfString:@"../../../lib/js-ios.js" withString:@"./js-ios.js"];


        NSLog(@"%@",html);
       [self.formswebview loadHTMLString:html baseURL:[NSURL fileURLWithPath:idataPath]];



    }
`

但这不是加载css文件。任何人都可以指导我哪里出错了?

0 个答案:

没有答案