问题
**When I Use self.myWeview.delegate = self ,
UIWebView can not load URL in UIWebView...
But If I set it to self.myWeview.delegate = nil,
then methods(delegate) can't load but URL is load
this is the code:---
{
self.myWeview.delegate = nil;
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
}
This is working fine but couldn't called delegate methods.
On the other hand
{
self.myWeview.delegate = self;
NSURL *url = [NSURL URLWithString:@"http:http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
}
It Couldn't load URL but calls the delegate methods
回答1:
Finally I got my answer by lot of experiment,if we not using this method
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
except that all methods are working fine in UIwebViewDelegate
1. -(void)webViewDidFinishLoad:(UIWebView *)webView
2. -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
3. -(void)webViewDidStartLoad:(UIWebView *)webView
回答2:
remove that extra http
{
self.myWeview.delegate = self;
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[myWebView loadRequest:request];
}
回答3:
You have made the mistake in calling the URL ...
Try this :
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
回答4:
Use this code in your viewcontroller.h file
@interface ViewController : UIViewController<UIWebViewDelegate>
回答5:
set delegate to self then you need to implement the delegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}
and also don't forget to confirm the protocol in .h file like this
@interface YourViewController : UIViewController<UIWebViewDelegate>
来源:https://stackoverflow.com/questions/17289990/uiwebview-delegate-methods-not-working