2014-10-10 38 views
1

我試圖讓2個.js文件和一個.css文件通過一個HTML文件(正在被發現)加載到iOS上的UIWebView應用程序中, ..但它不工作..在xcode6中添加2個.js文件和一個.css文件到UIWebView

這些文件在構建階段等已經複製的複製包資源..

這是到目前爲止的代碼在ViewController.m

@implementation ViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"game1" ofType:@"html" inDirectory:nil]; 
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil]; 
    //Append javascript 
    NSString *script = @"<script src>TheScript4.js</script>"; 
    htmlString = [htmlString stringByAppendingString:script]; 
    [self.webview loadHTMLString:htmlString baseURL:nil]; 
} 

我m正在運行xcode6 ..

在正確的方向等任何幫助將是巨大的,非常感謝..

回答

1

您必須指定作爲基本URL的束路徑

[self.webView loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]]; 

此外,JavaScript字符串應該是這樣

NSString *script = @"<script src="TheScript4.js"></script>"; 

但是您將此腳本附加到html文件的末尾,該文件位於</html>結尾標記之後,因此可能無法執行。

相關問題