我试图使用该函数来调用一个HTML页面的JavaScript调用的Javascript -使用UIWebView的
View did load function
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *writablePath = [documentsDirectory stringByAppendingPathComponent:@"BasicGraph.html"];
NSURL *urlStr = [NSURL fileURLWithPath:writablePath];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *myPathInfo = [[NSBundle mainBundle] pathForResource:@"BasicGraph" ofType:@"html"];
[fileManager copyItemAtPath:myPathInfo toPath:writablePath error:NULL];
[graphView loadRequest:[NSURLRequest requestWithURL:urlStr]];
}
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
[graphView stringByEvaluatingJavaScriptFromString:@"methodName()"];
}
下面是HTML页面的JavaScript -
<script>
function methodName()
{
// code to draw graph
}
然而,函数methodName()
没有被调用,但在window.onload = function()之后,一切正常。
我正在尝试将RGraphs整合到我的应用程序中,并且Basic.html
是写入javascript的html页面。
这将是巨大的,如果有人可以帮助我了这一点。
嘿,如果你不介意,你可以请你分享你的示例代码,我可以从本地iOS代码调用rgrpahs吗?这将是非常有益的。从上一个星期我努力使它工作。 – iamMobile 2012-07-27 11:12:07
我刚刚在UIWebview的Javascript运行主题上创建了一个优雅的演示,请参考:http://creiapp.blogspot.hk/2013/04/uiwebview-javascript.html – 2013-04-18 05:43:49