2012-05-11 86 views
0

我的應用程序有一個RSS tableView和另一個WebView的頁面。我可以打開的WebView用任何物體在RSS的點擊,但我無法通過鏈接並在web視圖顯示網站 下面是我的代碼RSS鏈接將在WebView(iOS)中打開

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

} 

感謝您的幫助!

回答

0

假設UIWebView在您的DetailsViewController中,您必須在DetailsViewController中的WebView中設置URL。

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

謝謝,但沒有奏效,我的問題在於使用storyLink作爲全局字符串。 webView在DetailsViewController中看不到storyLink – user1279453

+0

我找到了另一個解決方案,我需要的是使用globel字符串將「storyLink」傳遞給webView。儘管如此,非常感謝您抽出時間 – user1279453