2011-09-13 45 views
0

如何將目標C中的數組顯示爲HTML或JavaScript,以顯示內容陣列上的HTML一個buttonclick,如何將目標C中的數組顯示到HTML或JavaScript中,以在HTML中按鈕單擊顯示數組的內容

下面的代碼是我的.m文件代碼的

[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> 

當我運行這個編程的,它顯示未定義的警報輸出,我是否缺少HTML文件中的任何代碼或我犯的錯誤。

回答

相關問題