Ios UIWebView URL截取
我试图在使用Ios UIWebView URL截取,ios,uiwebview,Ios,Uiwebview,我试图在使用UIWebView时拦截URL更改。我当前打开了一个URL()。但是,我想知道用户何时通过点击谷歌网页上的任何按钮来更改URL。然后,我想在加载新页面之前做一些事情 我试过: - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType 但是,当URL更改时,它
UIWebView
时拦截URL更改。我当前打开了一个URL()。但是,我想知道用户何时通过点击谷歌网页上的任何按钮来更改URL。然后,我想在加载新页面之前做一些事情
我试过:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
但是,当URL更改时,它似乎不会被调用。我在控制台中没有收到任何日志,即使返回的bool为“NO”,它也会加载页面
我也尝试过:
- (void)webViewDidStartLoad:(UIWebView *)webView
但是,该选择器似乎也没有被调用是否有人知道在加载新站点之前检测URL更改并执行某些操作的方法?我的代码如下:
@synthesize webView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
NSString *urlAddress = @"http://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.
[webView loadRequest:requestObj];
UIView *tabBar = [self.navigationController.view.superview viewWithTag:100];
tabBar.hidden = YES;
self.navigationController.view.frame = RECT_PERSONETICS_FRAME;
}
- (void)webViewDidFinishLoad {
// Other stuff if necessary...
// Could use hidden instead of enabled if you don't even want
// the button to be visible
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
}
- (void)webViewDidStartLoad:(UIWebView *)webView
{
NSLog(@"Webview URL: %@",[[[webView request] URL] absoluteString]);
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"New URL is: %@", request);
return NO;
}
由于没有调用方法,我假设您可能没有在
viewController
中设置,或者webview
出口设置不正确 您是否设置了webview的委托?你发布的代码中没有设置。哦,是的,这就是问题所在。真不敢相信我竟然忘了做那件事。谢谢