I had a CSV file where now i am able to read the CSV File contains as an array now. In my xcode Project i have created a Html file where i have to print the contains of the array on the onclick of a button.How to do this.
The following is the Code of my .m file,
[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]);
In the Html File, the following is the Code,
<head>
<title></title>
</head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
var srcFrame;
//External content into a layer
function loadOuter(doc) {
srcFrame = document.getElementById("hiddenContent");
srcFrame.src = doc;
// workaround for missing onLoad event in IFRAME for NN6
if (!srcFrame.onload) {
setTimeout("transferHTML()", 1000)
}
}
function transferHTML(){
srcContent='';
if (srcFrame.contentDocument){
srcContent=srcFrame.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
}
else if (srcFrame.contentWindow){
srcContent=srcFrame.contentWindow.document.body.innerHTML;
}
document.getElementById("outerDisplay").innerHTML = srcContent
}
var DocAry=new Array('lines');
function SelectList(v){
if (v>0){
loadOuter(DocAry[v-1]);
}
}
//-->
</script>
<INPUT TYPE="button" VALUE="lines" onClick="loadOuter('lines')" >
<br>
<div id="outerDisplay"></div>
<iframe id="hiddenContent" width="200" height="200" style="position:absolute;visibility:hidden;" ></iframe>
</body>
I am missing some code,i.e, How to give link so that the array which is in .m file is linked to the Html File,So that in Html file i can display the contents of array on OnClick.
Well, you actually have already almost everything you need. Just split the array
linesand get its strings, (you might be looking atobjectAtIndex) and save them.On the other hand, you need to know where your HTML file is, I am sure you know how to do that. The most convenient solution would be to save the HTML to a string and create a new string with your strings from lines and then save the new string to an html again, either under the same or under another name.
Please let me know if you had success.