简体   繁体   English

如何在iOS的UIWebView中打开链接?

[英]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. 我制作了一个显示宝莱坞新闻的应用程序,为此我制作了UITableView ,每个单元格都包含Nes,并且每个单元格都被选中,然后我想使用其链接重定向到UIWebView So how it possible to pass a URL to UIWebView . 那么如何将URL传递给UIWebView

Here My Code for didSelectRowAtIndexPath : 这是我的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 这里的所有数据都来自JSON数据这里的字典键值是“链接”,每个链接都包含每个单元格的相对URLLink,我想打开该链接到UIWebView 。我为此创建了一个UIWebView控制器,但不知道如何传递链接到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 现在在WebViewController.m中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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