单击UIWebView中的链接将推送到NavigationView堆栈 [英] Clicking a link in UIWebView pushes onto the NavigationView stack
问题描述
基本上,我想知道如何拦截网页浏览中的点击,然后弹出一个新视图,顶部有一个导航栏(带后退按钮),内容是我点击的链接。
Basically, I'd like to know how to intercept a click in a webview and then have a new view pop up that has a navigation bar at the top (with a back button) and the content to be the link I clicked.
我目前有一个带有5个标签的标签栏模板,每个标签当前都设置为NavigationView,每个标签内部都包含一个UIWebView视图。这是我处理链接的方式:
I currently have a tab bar template with 5 tabs and each tab is currently set to NavigationView and inside each of those tabs are views that contain a UIWebView. This is how I handle links:
-(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSRange page = [ urlString rangeOfString: @"/?page=" ];
// URL is main page
if ( [ urlString isEqualToString: @"http://somelink-yadayadayada.com/" ] ) {
return YES;
}
// URL contains page number
else if ( page.location != NSNotFound ) {
return YES;
}
// URL is clicked link
else {
// THIS IS WHERE I NEED TO HAVE THE LINK OPEN THE NEW NAV VIEW.
return NO;
}
}
如果我需要,我们将非常感谢任何帮助提供更多背景信息我很乐意这样做。谢谢。
Any help would be greatly appreciated and If i need to provide more context I'll be happy to do so. Thanks.
推荐答案
此问题之前已被多次询问过。请查看此页面,它几乎就是您所需要的,只需将 [BrowserViewController openBrowserWithUrl:url];
更改为将新ViewController推送到导航堆栈所需的任何内容。它可能看起来像这样:
This question has been asked many times before. Please have a look at this page, it's almost exactly what you need, just change the [BrowserViewController openBrowserWithUrl:url];
to whatever you need to push your new ViewController to the navigation stack. It might look like that:
LatestView *latestView = [[LatestView alloc] initWithNibName:@"LatestView" bundle:nil];
//Pass the URL here, depends on how you passed it into the WebView in the first place
// Add the ViewController to the stack
[self.navigationController pushViewController:latestView animated:YES];
[latestView release];
这篇关于单击UIWebView中的链接将推送到NavigationView堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!