Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

iphone - 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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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];   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...