2016-02-05 133 views
-1

我是目標c新手。我正在學習segue和PrepareForSegue。所以我有一個用戶保存的隨機鏈接的表格視圖。我想讓用戶點擊鏈接並轉到Web視圖以查看網頁。但是,每次點擊鏈接時,網頁都是空的。WebView未加載?

表視圖。米

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
if ([[segue identifier] isEqualToString:@"showArticle"]) { 

    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow]; 

    NSString *urlString = [NSString stringWithFormat:@"http://%@", _toDoItems[indexPath.row]]; 
    [[segue destinationViewController] setUrl:urlString]; 

WebView.m

- (void)viewDidLoad { 
[super viewDidLoad]; 

NSURL *URL = [NSURL URLWithString:[self.url 
            stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; 

NSURLRequest *request = [NSURLRequest requestWithURL:URL]; 
[self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://%@", request]]]]; 
// Do any additional setup after loading the view. 

}

+0

你在iOS 9.0上試試這個嗎? –

+0

如果您可以將您的destinationViewcontroller作爲Web視圖的委託,那將是一件好事。然後實現UIWebView的UIWebView委託方法,並在shouldStartLoadWithRequest中放置一個斷點:例如。然後,您可以調試您的Web視圖是否至少嘗試加載請求。 您也可以爲UIWebViewDelegate實現webDidFinishLoading和其他委託方法。 – iOSAddicted

+0

是@Vishnugondlekar – Liz

回答

0

這些鍵添加到您的info.plist。在iOS中9,你必須使用https://,而不是http://

Info.plist

這裏是鏈接配置應用程序傳輸安全 App Transport Security

確保通過這條線你urlString回報切不可無。它必須是一個有效的網址在您的瀏覽器中工作:

NSString *urlString = [NSString stringWithFormat:@"http://%@", _toDoItems[indexPath.row]];