[英]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
- (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);
}
nslog 結果是
<NSURLRequest http://www.google.com>
<UIWebView: 0xbb17ff0; frame = (0 0; 320 370); layer = <CALayer: 0xbb12f20>> (null)
根據該站點的建議,我將其從 IB 更改為代碼。我將 class 確認為 uiwebview 代表。webviewdidstart 和 Z5A98E2840FD0141780D854E48C608D4
webviewdstart
webView-----><NSMutableURLRequest >
webView-----><NSMutableURLRequest http://www.google.com>
webview 完成了
webView-finished----><NSMutableURLRequest http://www.google.com>
webView-finished----><NSMutableURLRequest http://www.google.com>
仍然沒有被調用,我認為這兩種方法都被調用了兩次
這是一個工作代碼,在您的應用程序中測試它並讓我們知道結果
在.h文件中,添加UIWebViewDelegate
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];
如果您的頁面正在加載,現在檢查代表:
- (void)webViewDidStartLoad:(UIWebView *)webView {
NSLog(@"page is loading");
}
-(void)webViewDidFinishLoad:(UIWebView *)webView {
NSLog(@"finished loading");
}
像這樣嘗試
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.