如何阻止UIWebView立即加载URL?

时间:2013-02-15 09:25:31

标签: iphone objective-c uiwebview

我想停止WebPage加载UIWebView,同时传递另一个URL进行加载。

2 个答案:

答案 0 :(得分:5)

你应该实现:

- (BOOL)webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType

UIWebViewDelegate协议的方法,并为您不想加载的所有网址返回NO

示例:

- (BOOL)webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ([[inRequest URL] isEqual:someMyUrl]) {
        return YES;
    }
    return NO;
}

答案 1 :(得分:1)

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]];