Reputation: 4167
I am trying to send an array to a javascript function via objective C.
I call the javascript function from my code by -
stringByEvaluatingJavaScriptFromString
I am now trying to pass an array of values to the javascript function.
This is what I tried -
- (void) webViewDidFinishLoad:(UIWebView *)webView
{
NSArray *array = [NSArray arrayWithObjects:@"10",@"9",@"8", nil];
string = [[array valueForKey:@"description"] componentsJoinedByString:@","];
[graphView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName2(%@)", string]];
}
In my Javascript -
<script>
function methodName(val)
{
alert(val);
}
</script>
However, only the number 10 gets displayed on my alert message on the webview. So I feel I am doing something wrong. Could someone tell me what I am doing wrong? And also, I would need to convert that string back into an array in the javascript.
It would be great if someone could help me out with this.
Upvotes: 4
Views: 3516