单击 UIWebView 中的链接会推送到 NavigationView 堆栈

发布于 2024-09-25 10:17:56 字数 888 浏览 2 评论 0原文

基本上,我想知道如何拦截网络视图中的点击,然后弹出一个新视图,该视图顶部有一个导航栏(带有后退按钮),内容是我点击的链接。

我目前有一个带有 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;
    }
}

任何帮助将不胜感激,如果我需要提供更多上下文,我将很乐意这样做。谢谢。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2024-10-02 10:17:56

这个问题之前已经被问过很多次了。请查看此页面,这几乎正是您所需要的,只需将 [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];   

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];   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文