Reputation: 55
I want to change URL when webview is loading,can I do that ? For example:if I find the URL is "www.google.com", I want to Change it and continute loading it . My code is :
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.webView.delegate = self;
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com"]]];
}
But I don't want to do like this:
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)requestnavigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL isEqual:@"www.google.com"]) {
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.google.com.hk"]]];
return NO;
}
return YES;
}
Any other ways? Thank you.
Upvotes: 2
Views: 2262
Reputation: 1948
You can subclass UIWebView, and reimplement the loadRequest method, change if it match.
Upvotes: 2