2012-03-19 79 views
0

:我有一個代碼:iPhone:調用JS功能webViewDidFinishLoad

NSString *functionCall = [NSString stringWithFormat:@"setString(%@)", @"string"]; 
[self.myWebView stringByEvaluatingJavaScriptFromString:functionCall]; 

而且在Java腳本:

function setString(string) { 
    alert(string); 
} 

,但我沒有看到警報時webView的成品負荷......我做什麼錯了?謝謝。

回答

1

您正試圖調用Objective-C方法。您必須將javascript代碼傳遞給stringByEvaluatingJavaScriptFromString方法。

你可能想要做的是這樣的:

NSString *functionCall = [NSString stringWithFormat:@"alert('%@');", @"string"]; 

[self.myWebView stringByEvaluatingJavaScriptFromString:functionCall]; 
1

嘗試插入引號:

NSString *functionCall = [NSString stringWithFormat:@"setString('%@')", @"string"]; 
[self.myWebView stringByEvaluatingJavaScriptFromString:functionCall];