uiwebview 未加载网页 [英] uiwebview not loading the web page

查看:23
本文介绍了uiwebview 未加载网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的程序中,uiwebview 没有加载 url 地址.当我登录时,请求对象不为 null.但是,当我登录 webview.request 时,它返回 null.它没有加载的原因可能是什么

 - (void)viewDidLoad {[超级viewDidLoad];self.web = [[UIWebView alloc] init];NSString *urlAddress = @"http://www.google.com";NSURL *url = [NSURL URLWithString:urlAddress];NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];NSLog(@"%@",requestObj);[self.web loadRequest:requestObj];[web setFrame:CGRectMake(0, 0, 320, 370)];NSLog(@"%@ %@",self.web,self.web.request);}

nslog 结果是

<UIWebView: 0xbb17ff0;帧 = (0 0; 320 370);层=<CALayer:0xbb12f20>>(空值)

根据本网站的建议,我将其从 IB 更改为代码.我让该类确认为 uiwebview 委托.webviewdidstart 和 webview 都被调用,这些是这些方法的 nslog 输出

webviewdidstart

webView----->webView-----><NSMutableURLRequest http://www.google.com>

webview 完成了

webView-finished----><NSMutableURLRequest http://www.google.com>webView-finished----><NSMutableURLRequest http://www.google.com>

仍然没有被调用,我认为这两种方法都被调用了两次

解决方案

这是一个有效的代码,请在您的应用程序中测试它并让我们知道结果

在.h文件中,添加UIWebViewDelegate

在.m文件的viewDidLoad中,添加:

UIWebView *webview=[[UIWebView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,460.0)];NSURL *url = [NSURL URLWithString:@"http://www.google.com"];NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];webview.delegate = self;[webview loadRequest:requestObj];[self.view addSubview:webview];

现在检查代表是否正在加载您的页面:

- (void)webViewDidStartLoad:(UIWebView *)webView {NSLog(@"页面加载中");}-(void)webViewDidFinishLoad:(UIWebView *)webView {NSLog(@"加载完成");}

in my program uiwebview is not loading the url address.when i nslogged the request object is not null.however when i nslog the webview.request it returns null.what may be the reason it is not loading

 - (void)viewDidLoad {
        [super viewDidLoad];

        self.web = [[UIWebView alloc] init];
        NSString *urlAddress = @"http://www.google.com";
        NSURL *url = [NSURL URLWithString:urlAddress];
        NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

        NSLog(@"%@",requestObj);
        [self.web loadRequest:requestObj];
        [web setFrame:CGRectMake(0, 0, 320, 370)];
        NSLog(@"%@   %@",self.web,self.web.request);


    }

the nslog results are

<NSURLRequest http://www.google.com>
 <UIWebView: 0xbb17ff0; frame = (0 0; 320 370); layer = <CALayer: 0xbb12f20>>   (null)

as per suggestions from this site i changed it from IB and made it to code .i made the class confirm to uiwebview delegate..both the webviewdidstart and webview did finish are being called these are the nslog outputs from these methods

webviewdidstart

webView-----><NSMutableURLRequest >
webView-----><NSMutableURLRequest http://www.google.com>

webview did finish

webView-finished----><NSMutableURLRequest http://www.google.com>
webView-finished----><NSMutableURLRequest http://www.google.com>

still nothing is being called and i think both these methods are called twice

解决方案

This is a working code, test this out in your application and let us know the outcome

in .h file, add UIWebViewDelegate

in .m file's viewDidLoad, add this:

UIWebView *webview=[[UIWebView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,460.0)];
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
webview.delegate = self;
[webview loadRequest:requestObj];
[self.view addSubview:webview];

Now check in the delegates if your page is loading or not:

- (void)webViewDidStartLoad:(UIWebView *)webView {     
   NSLog(@"page is loading");       
 }

-(void)webViewDidFinishLoad:(UIWebView *)webView {
       NSLog(@"finished loading");
 }

这篇关于uiwebview 未加载网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆