-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.
}
你在iOS 9.0上試試這個嗎? –
如果您可以將您的destinationViewcontroller作爲Web視圖的委託,那將是一件好事。然後實現UIWebView的UIWebView委託方法,並在shouldStartLoadWithRequest中放置一個斷點:例如。然後,您可以調試您的Web視圖是否至少嘗試加載請求。 您也可以爲UIWebViewDelegate實現webDidFinishLoading和其他委託方法。 – iOSAddicted
是@Vishnugondlekar – Liz