我收到HTML格式的描述文本,並且我在webview中加載它,如果鏈接在描述中單擊,所以我將它加載到單獨的視圖控制器中。但是,shouldStartLoadWithRequest會給出一些附加鏈接。這裏是我的代碼shouldStartLoadWithRequest附加鏈接與applewebdata
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
WebsiteViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"WebsiteViewController"];
vc.url = request.URL.absoluteString;
NSLog(@"link is : %@", [[request URL] absoluteString]);
[self.navigationController pushViewController:vc animated:YES];
return false;
}
return true;
}
它打印此
link is : applewebdata://038EEEBF-A4C9-4C7D-8FB5-32056714B855/www.yahoo.com
和我加載像這樣
[webViewDescription loadHTMLString:description baseURL:nil];
我應該爲baseURL而不是baseURL:無? – 2013-09-19 09:50:19
我遇到了這個問題,爲了讓鏈接正確加載,我將基URL設置爲@「http://」 – BreadicalMD 2013-10-18 21:56:58
只是一個小小的修復。 baseURL參數需要一個NSURL對象,所以它應該是'[NSURL URLWithString:@「http://」]'不是'@「http://」'。 – Hlung 2013-11-25 10:50:55