[英]How to open a link in UIWebView in iOS?
我制作了一個顯示寶萊塢新聞的應用程序,為此我制作了UITableView
,每個單元格都包含Nes,並且每個單元格都被選中,然后我想使用其鏈接重定向到UIWebView
。 那么如何將URL
傳遞給UIWebView
。
這是我的didSelectRowAtIndexPath
代碼:
我的代碼在這里:
-(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]];
}
這里的所有數據都來自JSON
數據這里的字典鍵值是“鏈接”,每個鏈接都包含每個單元格的相對URLLink,我想打開該鏈接到UIWebView
。我為此創建了一個UIWebView
控制器,但不知道如何傳遞鏈接到UIWebView
怎么可能,請給我解決方案。
-(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];
}
現在在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.