RSS链接在WebView(iOS)中打开

时间:2012-05-11 18:10:39

标签: ios uitableview rss webview nsstring

我的应用程序有一个RSS tableView,另一个页面有一个WebView。我可以通过点击RSS中的任何项目打开WebView但我无法传递链接并在WebView中显示网站 下面是我的代码

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

    int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];

    NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: @"link"];


    // clean up the link - get rid of spaces, returns, and tabs...
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@" " withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    storyLink = [storyLink stringByReplacingOccurrencesOfString:@"  " withString:@""];


    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    browserScreen = [[DetailsViewController alloc] initWithNibName:@"DetailsViewController" bundle:nil];
    [self.view addSubview:browserScreen.view];


    // open in Safari --> this line works perfect but I want to open the link in my own Webview so I commented it out
    //[[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];

 }

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

假设UIWebView位于DetailsViewController中,则必须在DetailsViewController中的WebView中设置URL。

browserScreen.webView.request = [NSURLRequest requestWithURL:[NSURL URLWithString:storyLink]];