2012-06-19 32 views
0

我有一個UIWebView,其中包含Web鏈接。該測試正在從數據庫中顯示。UIWebview未檢測到鏈接

對於文本中的某些鏈接,UIWebView會檢測鏈接,而對於某些鏈接則不會。在數據庫中,所有鏈接都以相同的格式寫入,在空格之後,我有鏈接。請幫助我,爲什麼一些鏈接工作,而不是?

在此先感謝。

NSString *newString =[NSString stringWithFormat:@"<html><script> document.ontouchmove = function(event) { if (document.body.scrollHeight == document.body.clientHeight) event.preventDefault(); } </script><script type='text/javascript'>function myFunction() { window.open('http://www.otherlink.com');} function myFunction1(){window.open('http://www.newlink.com');}</script><style type='text/css'>.layout {padding:6px 10px 12px; width:300px; height:398px} *{padding:0; margin:0;line-height:normal}img{margin-bottom:10px;width:300px} button{padding-bottom:7px; border:none; text-decoration:underline;text-align:right;float:right; font-family:ArnhemPro-Blond; font-size:13px; color:#666666}.headline {color:#000000; font-family:PublicoHeadline-Light; font-size:28px; padding-bottom:4px;}.subHeadLine {color:#585c74; font-family:ApexNew-Book;margin-bottom:10px;font-size:14px;}.fullText {font-size:13px;font-family:ArnhemPro-Blond;margin-bottom:7px;} .fullText p { color:black; font-size:13px; margin-bottom:7px} .fullText a { text-decoration: underline; color: #A6091E; font-weight:bold;} .clr {clear:both;} </style> <body><div class='layout'><p class='headline'>%@</p><p class='subHeadLine'>%@</p><img src='%@'/><p class='fullText'>%@</p><button onclick='myFunction()'>Try it</button><div class ='clr'></div><button onclick='myFunction1()'>Try it Next</button></div></body></html>",headLine,subHeadLine,path,fullText] ; 

它顯示文本+圖像+ 2按鈕。

+0

你能告訴我們UIWebview的內容嗎? –

+0

它是HTML字符串,如果您的意思是顯示文本,那麼我將粘貼它,或者您的意思是HTML字符串。 – fibnochi

+0

我們希望看到html字符串。 –

回答

0

這是一個編碼問題。只是改變編碼爲

NSUTF8StringEncodeing和問題已解決。

+0

你在哪裏添加了這行代碼與NSUTF8字符串編碼?我看到了字符串,你想在你的webview中加載,我說得對嗎?你用[webview loadHTMLString:<上面的文本> baseURL:nil]加載內容?我面臨同樣的問題,我試圖找到simulus。最好的問候 – NicTesla

+0

是的我用loadHTMLString方法加載內容。有一個編碼問題,因爲webview使用默認編碼,當嘗試NSUTF8時,它工作。我想看看你的代碼(HTML字符串),你如何做到這一點。 – fibnochi