开发者

How to distinguish between link requests in Objective-C

I have the following method in a UIViewController:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWe开发者_开发知识库bViewNavigationType)navigationType.

My webview has two links in the view; I want to be able to distinguish between the two of them so that I know which one the user clicked on.

Does anyone know how to?


You must extract a url string from NSURLRequest:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
    NSURL *requestUrl = [request URL];
    NSString *currentPath = [requestUrl path];
...
}

Then use currentPath to compare with your two URLs. If those URL are unknown you should parse your html file to find them in it. You cannot get access to HTML document structure through UIWebView because it is extremely complicated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜