Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/108.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UIWebView的JavaScript代码_Javascript_Ios_Objective C - Fatal编程技术网

UIWebView的JavaScript代码

UIWebView的JavaScript代码,javascript,ios,objective-c,Javascript,Ios,Objective C,我对JavaScript一无所知,但我们的团队需要使用一些简单的代码在iOS项目的UIWebView中进行评估 所以我可以在UiWebView委托中使用javascript代码,比如 - (void)webViewDidFinishLoad:(UIWebView *)webView { [activityView stopAnimating]; NSData *data = [NSJSONSerialization dataWithJSONObject:[[MarketingMa

我对JavaScript一无所知,但我们的团队需要使用一些简单的代码在iOS项目的UIWebView中进行评估

所以我可以在UiWebView委托中使用javascript代码,比如

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [activityView stopAnimating];
    NSData *data = [NSJSONSerialization dataWithJSONObject:[[MarketingMachine instance] userState] options:NSJSONWritingPrettyPrinted error:nil];
    NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    string = [string stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    string = [string stringByReplacingOccurrencesOfString:@"'" withString:@""];
    NSString *js = [NSString stringWithFormat:@"var str = '%@';\
                                            var userState = JSON.parse(str);", string];
    [webView stringByEvaluatingJavaScriptFromString:js];
}
因此,我添加了类似于var的NSDictionary并对其进行评估

你能告诉我使用我的字典我必须用html做什么吗。所以我需要从这本字典中得到数字,并把它们画在图片上

例如,我现在正在测试html。如何向脚本中添加一些代码,这些代码将在我添加-voidwebViewDidFinishLoad:UIWebView*webView必需数据后执行?因此,我将用html编写一些代码,但要从html调用我的代码,我必须在UIwebView中计算哪些代码

<html>

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=302; user-scalable=no">
<meta name="app_scheme" content="fb1434788">

<style type="text/css">

a {
    -webkit-tap-highlight-color:rgba(0,0,0,0);
}   

#container {
    position:relative;
}

#img_logo {
    position: absolute;
    left: 0px;
    top: 805px;
}


#img_logo2 {
    position: absolute;
    left: 0px;
    top: 105px;
}
</style>


</head>

<script type="text/javascript">
function drawShape(){
  // get the canvas element using the DOM
  var canvas = document.getElementById('mycanvas');

  // Make sure we don't execute when canvas isn't supported
  if (canvas.getContext){

    // use getContext to use the canvas for drawing
    var ctx = canvas.getContext('2d');

    // Filled triangle
    ctx.beginPath();
    ctx.moveTo(25,50);
    ctx.lineTo(105,50);
    ctx.lineTo(25, 300);
    ctx.fill();

    // Stroked triangle
    ctx.beginPath();
    ctx.moveTo(125,125);
    ctx.lineTo(125,45);
    ctx.lineTo(45,125);
    ctx.closePath();
    ctx.stroke();

  } 
}
</script>

<body onload="drawShape();" marginwidth="0" marginheight="0" >
<canvas id="mycanvas"></canvas>
<div id="container">
    <img src="meat_iphone.jpg" id="img_back" width="604" height="908"/>

    <a href="do://"><img src="meat_iphone_btn.png" id="img_logo"/></a>


    <a href="close"><img src="meat_iphone_close.png" id="img_logo2"/></a>
</div>

</body>
</html>