小编Mat*_*lee的帖子

使用uiwebview中的本地html从相对路径加载资源

我有一个非常简单的iOS应用程序,带有uiwebview加载一个非常简单的测试页面(test.html):

<html>
<body>
<img src="img/myimage.png" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

我将此test.html文件加载到我的Web视图中:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"test" withExtension:@"html"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSURL *baseUrl = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[webView loadHTMLString:html baseURL:baseUrl];
Run Code Online (Sandbox Code Playgroud)

如果我在没有相对路径的情况下引用图像并将引用的图像放在根目录下的根目录下 - >在XCode中复制捆绑资源,这可以正常工作,但是我无法使用我的html文件中显示的相对路径.必须有一种方法可以做到这一点,我有很多图像,CSS,javascript文件,我想加载到webview中,我希望不必拥有根目录中的所有内容,并且必须更改我的网站中的所有引用应用程序.

uiwebview ios

120
推荐指数
4
解决办法
11万
查看次数

在JavaScript中为Google Closure编译器注释Singleton对象,或"危险使用全局此对象"警告

我正在使用ADVANCED_OPTIMIZATIONS编译级别的Google Closure Compiler并开始注释我的构造函数,因为我收到了各种警告:

警告 - 危险使用全局此对象

对于我的'构造函数'类型函数,我将像这样注释它们:

/**
 * Foo is my constructor
 * @constructor
 */
Foo = function() {
   this.member = {};
}

/**
 * does something
 * @this {Foo}
 */
Foo.prototype.doSomething = function() {
   ...
}
Run Code Online (Sandbox Code Playgroud)

这似乎工作得很好,但是如果我有一个'singleton'对象不是用var myFoo = new Foo()构造的呢?我在文档中找不到如何注释这种类型的对象,因为它的类型只是对象吗?

Bar = {
   member: null,
   init: function() {
      this.member = {};
   }
};
Run Code Online (Sandbox Code Playgroud)

javascript google-closure-compiler jsdoc

4
推荐指数
2
解决办法
2343
查看次数