基本上,我想知道如何拦截webview中的点击,然后弹出一个新视图,顶部有一个导航栏(带后退按钮),内容是我点击的链接.
我目前有一个带有5个选项卡的标签栏模板,每个选项卡当前都设置为NavigationView,每个选项卡内部都是包含UIWebView的视图.这就是我处理链接的方式:
-(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; } }
任何帮助将不胜感激,如果我需要提供更多的背景,我将很乐意这样做.谢谢.
之前已经多次询问过这个问题.请看一下这个页面,它几乎就是你需要的,只需将[BrowserViewController openBrowserWithUrl:url];
你需要的东西更改为将新的ViewController推送到导航堆栈.它可能看起来像这样:
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];