[英]iPhone: what's the best way to display a "report'?
我有一個應用程序,需要在其中顯示六(6)列和可變數量的行(行)的報告。
最好的方法是什么? 我嘗試了UITextView,但是無法設置字體大小以使數據適合每一行。
我通常為此使用UIWebViews。
用NSArray和一些不錯的CSS創建一行html表的十幾行代碼。
編輯:我可以向您展示我在最近5分鍾內編寫的示例。 如果您對html有基本的了解,那么就沒有太多了。 當然,您可以更進一步。
即使您對html一無所知,我相信您也可以在幾個小時內了解一些簡單表格顯示的基礎知識。
- (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];
}
該表應如下所示。 恕我直言,工作量還不錯。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.