You might think that if you add the jquery js file to your project, you can build and reference it from html you load into a UIWebView. That’s what I thought too. Here are the steps you need to take.
1. Add the jquery file to resources. Drag the file in, right-click and choose to add an existing file. Whatever you are comfortable with.
![]()
2. The file will be automatically added as source code. In Xcode under Targets, expand the target you are working on and you’ll find two groups, “Copy Bundle Resources” and “Compile Resources”.

3. Drag the file from the “Compile Sources” group

to the “Copy Bundle Resources” group.

This tells Xcode to package the file up and include it with your app as a resource instead of compiling it.
4. Include the reference to jQuery in your HTML.
html = [NSString stringWithFormat:@"<html><head><script type='text/javascript' src='jquery-1.4.2.min.js'></script></head><body>%@</body></html>", body];
5. Set the baseURL using the path to your jQuery file.
[myWebView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@”jquery-1.4.2.min.js” ofType:nil]]];
使用jQuery与UIWebView
本文详细介绍了如何将jQuery集成到iOS应用的UIWebView中。包括将jQuery文件添加为资源、设置Xcode项目的编译配置、在HTML中引用jQuery以及设置正确的baseURL。


被折叠的 条评论
为什么被折叠?



