2012-05-01 69 views
12

我經過許多小時尋找解決方案並嘗試不同的方法來解決與JQuery Mobile和我的iPad應用程序有關的問題。JQuery Mobile不能在UIWebView中工作

我想要做的是使用Fusion Charts的報告應用程序。我已經使用不同的方法成功地在Web視圖(UIWebView)中呈現了圖表,並遵循不同的示例,但我現在要做的是使用JQuery Mobile框架完成相同的任務。

我是不是使用phonegap,我遵循了關於JQuery Mobile + Xcode集成(我認爲)的信的步驟。圖表在我的桌面和移動瀏覽器(iPad,iPhone 4和iPod Touch 2G)上加載沒有問題,但是它們無法在我的UIWebView中加載(即使我使用的是相同的代碼)。

這是我在做什麼:

1)將所需的文件(JS,CSS和HTML)的項目,以在本地使用它們。添加它們後,我將.js擴展名中的所有內容從「編譯源代碼」移動到「複製軟件包資源」。它看起來像這樣:

enter image description here

enter image description here

2)加載我的HTML測試文件(page_A1.html)到Web視圖:

enter image description here

3)檢查一切在HTML文件上設置正確路徑和最新版本的框架:

enter image description here

4)構建並運行,以獲得空白的網絡視圖。

如果我測試JavaScript像這樣的警告:

enter image description here

它會顯示警告證明JavaScript是工作:

enter image description here

如果我把一些文字上的圖表應該顯示的容器:

enter image description here

我會得到Web視圖中的文本:

enter image description here

我也有遠程框架鏈接,而不是在本地的和舊版本沒有運氣庫的測試。沒有什麼不同的情況:

enter image description here

看來obvius,我認爲

$(document).ready(function(){ 

沒有被發現或Xcode的調用。

這是想什麼我來完成:

enter image description here

我不知道考什麼。如果你有任何想法,我會感激不盡。

回答

10

沒關係的傢伙。我終於明白了。

網絡發展日的一些舊習慣在這裏扮演着我的角色。

它大桶出來你沒有指定你的CSS內的目錄結構和js文件等等這樣的:

<link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css" /> 

<script src="js/jquery-1.7.2.min.js"></script> 

<script src="js/jquery.mobile-1.1.0.min.js"></script> 

shoudl真的是這樣在Xcode:

<link rel="stylesheet" href="jquery.mobile-1.1.0.min.css" /> 

<script src="jquery-1.7.2.min.js"></script> 

<script src="jquery.mobile-1.1.0.min.js"></script> 

難以置信我花了多少時間才發現這一點。

現在工作。

+1

那麼..你救了我的生命.. – rdurand

+0

我有同樣的問題,但手風琴測試。你可以幫我嗎? –

+0

這裏發佈的信息沒有幫助你嗎?如果不是,你遇到的具體問題是什麼? –

4

正確的做法是將JS文件加載到String中,然後調用UIWebView的[stringByEvaluatingJavascriptFromString:@「Javascript here ...」]方法。

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"content" ofType:@"js" inDirectory:@""]; 
NSData *fileData = [NSData dataWithContentsOfFile:filePath]; 
NSString *jsString = [[NSMutableString alloc] initWithData:fileData encoding:NSUTF8StringEncoding]; 

[webView stringByEvaluatingJavaScriptFromString:jsString]; 

儘管這並沒有太大的不同,然後將它們硬編碼到html文件中,但它確實模塊化了它。快樂編碼:)

+0

這對我有用! :-) 非常感謝。 – byJeevan