如何在HTML或JavaScript中显示objective C中的数组,如何在HTML中的按钮上显示数组的内容
如何在HTML或JavaScript中显示目标C中的数组,如何在HTML中的按钮上显示数组的内容 以下代码是我的.m文件代码如何在HTML或JavaScript中显示objective C中的数组,如何在HTML中的按钮上显示数组的内容,javascript,html,objective-c,arrays,Javascript,Html,Objective C,Arrays,如何在HTML或JavaScript中显示目标C中的数组,如何在HTML中的按钮上显示数组的内容 以下代码是我的.m文件代码 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Array"ofType:@"html"]isDirectory:NO]]]; NSString *path = [[NSBundl
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]pathForResource:@"Array"ofType:@"html"]isDirectory:NO]]];
NSString *path = [[NSBundle mainBundle] pathForResource:@"Example" ofType:@"csv"];
NSString *contents = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:nil];
NSArray *lines = [contents componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n,"]];
for (NSString* line in lines) {
NSLog(@"%@", line);
}
NSLog(@" %d", [lines count]);
[self.webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:[NSString stringWithFormat:@"checkContents = new Array%@",lines] waitUntilDone:NO];
下面是我的HTML文件代码
function checkContents(Lines) {
// alert("test...");
alert(checkContents[0]);
// alert(document.lines[0]);
if (typeof(checkContents)=='undefined')
....
else {
if (checkContents.length == 0)
....
else {
for (i=0; i<checkContents.length; i++) {
}
}
}
}
<body onload="checkContents()">
<div class="greybutton" onClick="javascript:checkContents()">contents</a></div>
</body>
功能检查内容(行){
//警报(“测试…”);
警报(检查内容[0]);
//警报(文档行[0]);
if(typeof(checkContents)=“未定义”)
....
否则{
如果(checkContents.length==0)
....
否则{
对于(i=0;i您可以使用CFArrayRef
这是一个C类,其中NSArray是它的obj-C版本。您可以动态更改类型,因此您可以更改它并使用发送到javascript的C-types字符串