简体   繁体   中英

iPhone: what's the best way to display a "report'?

I have an app where I need to display a report of six (6) columns and a variable number of rows (lines).

What's the best approach to do this? I tried UITextView but there is no way to set the font size to make the data fit on each line.

I usually use UIWebViews for this.

A dozen lines to create a html table out of a NSArray and some nice CSS.


Edit: I can show you an example I wrote in the last 5 minutes. There's not much to it if you have a basic understanding of html. Of course you could take it much further than that.
And even if you don't know anything about html I'm sure you can learn the basics for some simple table display within a couple of hours.

- (NSString *)htmlTableRowFromArray:(NSArray *)array withOpenTag:(NSString *)openTag andCloseTag:(NSString *)closeTag {
    NSMutableString *rowHtmlStr = [NSMutableString string];
    for (NSString *str in array) {
        [rowHtmlStr appendFormat:@"%@ %@ %@\n", openTag, str, closeTag];
    }
    return rowHtmlStr;
}


- (void)displayReport {
    NSArray *dataArray = ...;
    NSArray *myHeader = ...;

    NSMutableString *htmlStr = [NSMutableString stringWithString:@"<html><head><title>MyTable</title></head><body>"];

     // the table starts here
    [htmlStr appendString:@"<table width=\"100%\" style=\"background-color:#CCC\" border=\"1\" cellpadding=\"4\" cellspacing=\"0\">"];

    // this will create a table header
    [htmlStr appendFormat:@"<tr>%@</tr>", [self htmlTableRowFromArray:myHeader withOpenTag:@"<th>" andCloseTag:@"</th>"]];

    for (NSArray *line in dataArray) {
        // one row for each array in the data
        [htmlStr appendFormat:@"<tr>%@</tr>", [self htmlTableRowFromArray:line withOpenTag:@"<td>" andCloseTag:@"</td>"]];
    }
    // table ends
    [htmlStr appendString:@"</table>"];

    [htmlStr appendString:@"</body></html>"];

    [webView loadHTMLString:htmlStr baseURL:nil];
}

the table should look like this. Imho not that bad for the amount of work.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM