简体   繁体   English

UIWebView加载但不显示网站(XCode 4,iOS SDK 4.3)

[英]UIWebView loading but not displaying website (XCode 4, iOS SDK 4.3)

i'm going to write an app including an UIWebView. 我打算写一个包含UIWebView的应用程序。 So first I wanted to try it out by just simply loading an URL. 所以首先我想通过简单地加载URL来尝试一下。

  • Created the UIWebView in Interface Builder 在Interface Builder中创建了UIWebView
  • Hooked up to the code 迷上了代码

    @property(nonatomic,retain) IBOutlet UIWebView *webView;

viewDidLoad: viewDidLoad中:

- (void)viewDidLoad {
[super viewDidLoad];
if(!webView)
{
    webView = [[UIWebView alloc]init];
}

webView.delegate = self;

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]]; }

also I implemented the didFailLoadWithError and webViewDidFinishLoad delegate methods. 我也实现了didFailLoadWithError和webViewDidFinishLoad委托方法。 webViewDidFinishLoad is called and indicating that HTML has been loaded. 调用webViewDidFinishLoad并指示已加载HTML。

Problem is: Even though webViewDidFinishLoad is called, the UIWebView doesn't display the website. 问题是:即使调用了webViewDidFinishLoad,UIWebView也不会显示网站。 It's only showing white color. 它只显示白色。 The scroll bars right and at the bottom are shown when the UIWebView is touched and dragged but not content is visible. 触摸并拖动UIWebView但不显示内容时,会显示右侧和底部的滚动条。 Nowhere found anything. 没有找到任何东西。 Seems quite strange.. 看起来很奇怪..

EDIT This screenshot shows the connections of the xib: 编辑此屏幕截图显示了xib的连接:

Connections 连接

If you hooked everything up in Interface Builder correctly, the following lines should not be needed: 如果您正确地在Interface Builder中连接了所有内容,则不需要以下行:

if(!webView)
{
    webView = [[UIWebView alloc]init];
}

webView.delegate = self;

Try removing them and see what happens. 尝试删除它们,看看会发生什么。 Also, put an NSLog(...) in the webView:didFailLoadWithError: callback and see if it is output. 另外,在webView:didFailLoadWithError: callback中放置一个NSLog(...)并查看它是否输出。

I got it.. I used synthesize in the following way: 我明白了..我用以下方式合成:

@synthesize webView = _webView;

So it was necessary to call the UIWebView in the following way: 因此有必要以下列方式调用UIWebView:

[self.webView loadRequest:...];

New to this naming convention which is why i'm not used to necessity of self 这个命名惯例的新内容,这就是为什么我不习惯自我

Have you checked the File's Owner connect to the webView you declared? 您是否检查过文件所有者连接到您声明的webView?

Besides, webViewDidFinishLoad does not mean the HTML was loaded! 此外,webViewDidFinishLoad并不意味着HTML已加载! Whatever the content is loaded successful, this method will be called. 无论内容加载成功,都会调用此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM