开发者

iPhone : Problem with HTML while displaying it in UIWebView

开发者 https://www.devze.com 2023-03-26 02:36 出处:网络
In my app I am generating the report using html and displaying it in UIWebView. I am using Html table for formatting data in webview.

In my app

I am generating the report using html and displaying it in UIWebView.

I am using Html table for formatting data in webview.

Attaching some screen shot for better understanding :

iPhone : Problem with HTML while displaying it in UIWebView

iPhone : Problem with HTML while displaying it in UIWebView

As Shown in the second screen's first round mark up, table alignment is misplaced.

The code which I use for generating this table is as following.

 [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/>"];

How do I solve this problem ?


Use px or % to designate the width of the columns:

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

etc...

0

精彩评论

暂无评论...
验证码 换一张
取 消