2011-08-06 24 views
0

顯示它在我的應用程序iPhone:問題與HTML而在UIWebView的

我使用HTML生成的報告,並在UIWebView中顯示它。

我使用Html表格在webview中格式化數據。

附加一些屏幕截圖,以便更好地理解:

enter image description here

enter image description here

如圖所示的第二屏幕的第一輪標記,表對齊是錯誤的。

我用來生成此表的代碼如下。

[html appendFormat:@"<h3 style =\"font-family: Arial\">Expressive <h3><br/>"]; 

        NSString *htmlString1= @"<table border=\"1\" style=\"width: 100%; border: 1px #000 solid; border-collapse: collapse; font-size: 13px; font-family: sans-serif;\">"; 

        for (int i=0; i<2; i++) //Two Rows 
        { 
         htmlString1 = [htmlString1 stringByAppendingString:@"<tr>"]; 

         for (int j=0; j<2; j++) //Two Columns 
         { 
          if (i==0) 
          { 
           if(j==0) 
           { 
            htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<th style=\"text-align:center;font-size:16;width:30;height:20\"><b>Correct-%.00f%%</b></th>",correctPercent]]; 

           } 
           else if(j==1) 
           { 
            htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<th style=\"text-align:center;font-size:16;width:30;height:20\"><b>Incorrect-%.00f%%</b></th>",incorrectPercent]]; 

           } 

          } 
          else 
          { 
           if(j==0) 
           { 
            NSString *val = @""; 
            if([[[newArray valueForKey:@"Expressive"]valueForKey:@"CorrectResults"] count]>0) 
            { 
             val = [[[newArray valueForKey:@"Expressive"]valueForKey:@"CorrectResults"] componentsJoinedByString:@"<br/>"]; 
            } 
            htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<td style=\"text-align:center;width:40%;height:50;\">%@</td>",val]]; //E 

           } 
           else if(j==1) 
           { 
            NSString *val = @""; 
            if([[[newArray valueForKey:@"Expressive"] valueForKey:@"InCorrectResults"] count]>0) 
            { 
             val = [[[newArray valueForKey:@"Expressive"]valueForKey:@"InCorrectResults"] componentsJoinedByString:@"<br/>"]; 
            } 
            htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<td style=\"text-align:center;width:40%;height:50;\">%@</td>",val]]; 

           } 

          } 

         } 
         htmlString1 = [htmlString1 stringByAppendingString:@"</tr>"]; 
        } 

        htmlString1 = [htmlString1 stringByAppendingString:@"</table>"]; 

        [html appendString:htmlString1]; 
        [html appendString:@"<br/>"]; 

我該如何解決這個問題?

回答

0

使用px%指定列的寬度:

htmlString1 = [htmlString1 stringByAppendingString:[NSString stringWithFormat:@"<th style=\"text-align:center;font-size:16;width:30%;height:20px\"><b>Correct-%.00f%%</b></th>",correctPercent]]; 

等等

+0

我試圖用''%,但仍我沒有得到正確的HTML表! – Devang

+0

甚至嘗試使用「px」,但仍然無法正常工作。其他解決方案? – Devang

+1

如果%和px沒有做他們應該做的事,我不知道。請注意,這兩列的總和必須達到100%。如果您在設置一個寬度,也沒有必要將其設置在​​了。 –