简体   繁体   中英

How to open a link in UIWebView in iOS?

i make an app that shows Bollywood News For that i make UITableView and each cell contain Nes and each cell was selected then i want to redirect to UIWebView with its link. So how it possible to pass a URL to UIWebView .

Here My Code for didSelectRowAtIndexPath :

My Code here :

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary *dict = [self.imagesa objectAtIndex:indexPath.section];
NSString *link=[dict valueForKey:@"link"];
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:link]];
}

Here All Data is Come From JSON Data Here dictionary key Value is "link" and each link is Contain each cells relative URLLink i want to open that link in to UIWebView .i make for that a UIWebView Controller but not know how to pass a link to UIWebView

How it is Possible Please Give me solution.

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSDictionary *dict = [self.imagesa objectAtIndex:indexPath.section];

    NSString *link=[dict valueForKey:@"link"];

    //Create a URL object.
    NSURL *url = [NSURL URLWithString:link];

    WebViewController *webView=[[WebViewController alloc]initWithNibName:@"WebViewController" bundle:nil];
    webview.url = url; // pass URL to webview controller
    [self presentViewController:webView animated:YES completion:nil];
}

Now in WebViewController.m

- (void) viewDidAppear:(BOOL) animated {
    //URL Request Object
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];        
    //Load the request in the UIWebView.
    [webView loadRequest:requestObj];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM