2

Actually I have two related questions here, about different use cases of loading requests in a UIWebView.

  1. Is it safe to call - [UIWebView loadRequest:] on a web view that is inserted in the view hierarchy and its hidden property or the one of its superview is set to YES?
  2. Is it safe to call - [UIWebView loadRequest:] on a web view that is not inserted in the view hierarchy?

In particular I'm interested whether it is considered to be a good practice to load request in a UIWebView that is not visible, and whether the delegate assigned to the instance of UIWebView will be notified once the request succeeds/fails. The reason I'm asking is that UIWebView class reference says "create a UIWebView object, attach it to a window, and send it a request to load web content", where the part telling that a UIWebView should be attached to a window makes me doubt if the above approaches are reliable.

4

3 回答 3

3

我已经成功地将 [UIWebView loadRequest:] 与不在视图层次结构中的对象一起使用。我希望类引用只是假设视图将被显示,因为它可能是最常见的用例。

于 2014-02-18T13:23:19.487 回答
0

有用。只要您不使用任何私有 API 并遵循 HIG,该方法是完全可靠的。只要符合您的要求,这不是一个坏习惯。如果您有hidden可用的属性,UIWebView那么您当然可以根据您的要求隐藏 webView。

关于您的以下查询,它根据句子上下文写在文档中。

我问的原因是 UIWebView 类引用说“创建一个 UIWebView 对象,将其附加到窗口,并向其发送加载 Web 内容的请求”,其中告诉 UIWebView 应该附加到窗口的部分让我怀疑上述方法是否可靠。

完整的上下文如下,这显然意味着要使用 UIWebView 在您的应用程序中显示网页,您必须按照上述方式进行操作。

您可以使用 UIWebView 类将 Web 内容嵌入到您的应用程序中。为此,您只需创建一个 UIWebView 对象,将其附加到窗口,并向其发送加载 Web 内容的请求。

于 2014-02-19T18:08:30.100 回答
0
  1. 是的,在视图层次结构中插入的 web 视图上调用 [UIWebView loadRequest:] 是安全的。因为您将在视图中使用 web。此外,如果您只是在程序中提供 URL,就足够了.

    [UIWebView loadRequest] 的以下代码是

    NSString *strurl =@"http:www.google.com";
    NSURL *url=[NSURL urlWithString:strurl];
    NSURLRequest *urlrequest =[NSURLRequest requestWithUrl:url];
    [webView loadRequest:urlrequest];
    
  2. 即使在未插入视图层次结构的 Web 视图上调用 [UIWebView loadRequest:] 也是安全的。因为您可以通过程序动态创建视图并编写 Web 视图的代码。

于 2014-02-18T13:32:31.893 回答