Javascript 在xcode6中将2.js文件和.css文件添加到UIWebView
我正试图通过一个HTML文件(正在查找)将2.js文件和一个.css文件加载到iOS上的UIWebView应用程序中。。但它不起作用 这些文件已复制到构建阶段等下的复制包资源中 这是迄今为止ViewController.m上的代码Javascript 在xcode6中将2.js文件和.css文件添加到UIWebView,javascript,ios,css,objective-c,uiwebview,Javascript,Ios,Css,Objective C,Uiwebview,我正试图通过一个HTML文件(正在查找)将2.js文件和一个.css文件加载到iOS上的UIWebView应用程序中。。但它不起作用 这些文件已复制到构建阶段等下的复制包资源中 这是迄今为止ViewController.m上的代码 @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; NSString *htmlFile = [[NSBundle mainBundle] pathFo
@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];
}
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
NSString*htmlFile=[[NSBundle mainBundle]路径资源:@“game1”类型:@“html”目录:nil];
NSString*htmlString=[NSString STRINGWITHCONTENTSOFILE:htmlFile编码:NSUTF8STRING编码错误:nil];
//附加javascript
NSString*script=@“TheScript4.js”;
htmlString=[htmlString stringByAppendingString:script];
[self.webview加载htmlString:htmlString baseURL:nil];
}
我正在运行xcode6
任何正确方向的帮助都将非常好,非常感谢。您必须指定baseURL作为捆绑路径
[self.webView loadHTMLString:htmlString baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
另外,javascript字符串应该是
NSString *script = @"<script src="TheScript4.js"></script>";
NSString*script=@”;
但是您将此脚本附加到html文件的末尾,该文件将位于
结束标记之后,因此它可能不会执行