我正在使用以下网址加载一个网址:
[webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://abc-ecatalogue.xyz-ar.com/"]]];
然后我正在检查是否正在加载主页然后我不想要我正在使用的导航栏:
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
// Here you can check the URL
NSURL *url = [request URL];
NSString*str=@"http://abc-ecatalogue.xyz-ar.com";
if ([url.absoluteString isEqualToString:@"http://havells-ecatalogue.adstuck-ar.com/"])
{
self.navigationController.navigationBarHidden = YES;
NSLog(@"hello");
return NO;
}
else
{
self.navigationController.navigationBarHidden = NO;
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:self action:@selector(Back)];
self.navigationItem.leftBarButtonItem = backButton;
}
return YES;
}
但是当控件进入循环内部时,Web视图未加载,并且我打印的日志会不断打印。
答案 0 :(得分:1)
self.navigationController.navigationBarHidden = NO;
和if
中都有else
YES
部分。您应该在if部分将其更改为- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
// Here you can check the URL
NSURL *url = [request URL];
NSString*str=@"http://abc-ecatalogue.xyz-ar.com";
if ([url.absoluteString isEqualToString:@"http://havells-ecatalogue.adstuck-ar.com/"]) {
self.navigationController.navigationBarHidden = YES;
NSLog(@"hello");
} else {
self.navigationController.navigationBarHidden = NO;
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style: UIBarButtonItemStyleBordered target:self action:@selector(Back)];
self.navigationItem.leftBarButtonItem = backButton;
}
return YES;
}
。左编辑:
{{1}}