0

My goal is to allow UIWebView load initial link, but disallow any further navigation.

I saw question:

Disable hyperlinks in UIWebView

So, I wired referenced webView property from interface builder.

I specified that my UIViewController uses UIWebViewDelegate:

@interface LegalViewController : UIViewController<UIWebViewDelegate>

In the code, on viewDidLoad, I do following:

 mFirstLoad = TRUE;
 webView.delegate = self;

And I have following code:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (!mFirstLoad)
        return FALSE;

    mFirstLoad = FALSE;
    return TRUE;
}

shouldStartLoadWithRequest is called both initial call and when I click on the link. However, even if shouldStartLoadWithRequest returns FALSE, UIWebView still proceeds and loads a new page.

I see this problem on iOS Simulator 6.0

How can I fix this behavior?

4

3 に答える 3

2

タイプに基づいて NO を返し、リンクを除外します

return !(navigationTpe==UIWebViewNavigationTypeLinkClicked);

于 2012-12-03T23:39:07.300 に答える
0

ブール値が何らかの形でリセットされている可能性はありますか? に対して NO を返すとどうなります(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationTypeか?

于 2012-12-04T06:41:41.690 に答える
0

これは私がコメントに書いたものと同じです:

問題の原因がわかったと思います。それを適切に呼び出す方法がわかりません (HTML と Javascript の専門家ではありません)。ただし、リンクには次のコードがあります。"<a href="/something" data-transition="flip"</a>その結果、コールバックが呼び出されますが、このコールバックの結果は無視されるようです。

結果として、最も可能性の高い解決策は次のとおりです。uiwebviewのハイパーリンクを削除します

于 2012-12-04T22:35:09.440 に答える