我試圖加載UIWebView
,但我不明白爲什麼不工作,我這樣做:的UIWebView無法加載
Loading *load = [[Loading alloc] init];
[load searchName];
然後Loading.h
@interface Loading : NSObject <UIWebViewDelegate>
{
UIWebView *myWebView;
}
- (void) searchName;
Loading.m
- (void) searchName{
myWebView = [[UIWebView alloc] init];
myWebView.delegate = self;
NSString *urlAddress = @"www.google.com";
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
//Load the request in the UIWebView.
[myWebView loadRequest:requestObj];
}
- (void)webViewDidFinishLoad:(UIWebView *)thisWebView
{
NSString *yourHTMLSourceCodeString = [myWebView stringByEvaluatingJavaScriptFromString:@"document.body.innerHTML"];
NSLog(@"%@",yourHTMLSourceCodeString);
}
爲什麼從來不叫webViewDidFinishLoad
方法?
因爲你缺少你的URL中的http協議? – Lefteris
不,我也嘗試過http,但不起作用... – Piero
你嘗試過http://嗎?另外,你爲什麼要分配另一個webView?如果您使用的是.xib,那麼您應該附加webView,而不是分配一個新的。特別是因爲你從來沒有將webView添加到框架中。 – Josiah