简体   繁体   English

uiwebview 未加载 web 页面

[英]uiwebview not loading the web page

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 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 nslog 结果是

<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根据该站点的建议,我将其从 IB 更改为代码。我将 class 确认为 uiwebview 代表。webviewdidstart 和 Z5A98E2840FD0141780D854E48C608D4

webviewdidstart webviewdstart

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

webview did finish webview 完成了

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在.h文件中,添加UIWebViewDelegate

in.m file's viewDidLoad , add this: in.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];

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");
 }

try like this像这样尝试

 CGRect webFrame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];

NSString *urlAddress = @"http://www.google.com";
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
 [webView loadRequest:requestObj]; 
[self addSubview:webView]; 
[webView release];

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

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