webView ShouldStartLoadRequest方法无法正常工作

时间:2014-05-20 05:40:43

标签: ios uiwebview

我正在使用以下网址加载一个网址:

[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视图未加载,并且我打印的日志会不断打印。

1 个答案:

答案 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}}