Ios webView应使LoadRequest方法无法正常工作
我正在使用以下方式加载带有url的webview:Ios webView应使LoadRequest方法无法正常工作,ios,uiwebview,Ios,Uiwebview,我正在使用以下方式加载带有url的webview: [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://abc-ecatalogue.xyz-ar.com/"]]]; 然后,我正在检查是否正在加载主页,然后我不希望使用我正在使用的导航栏: - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLReques
[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视图不会加载,并且我打印的日志会继续打印。您有
self.navigationController.navigationBarHidden=NO在if
和else
部分中的code>。您应该在if部分将其更改为YES
。
编辑:
- (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;
}
你能在别的{}里放一个NSLog吗?请添加您以后看到的日志。我刚刚试用了您的代码,效果很好。NSLog(@“你好”);只印了一次。尝试执行“清理”项目,并从模拟器中删除应用程序,然后重试。您的代码似乎没有任何问题。当控件处于if状态时,它不会加载网页。它将变为空白。这是因为您在if块末尾返回NO。您需要将其更改为“是”以继续在webview中加载url或将其删除,因为您将在shouldStartLoadWithRequest的末尾返回“是”。我已经修改了您的代码,并将其添加为对我答案的编辑。看一看。