在你们的帮助下,我们提出了这个解决方案,它的工作非同寻常!
我正在使用一个带有标记的HTML“模板”文件和一个UIWebView。
我在做什么基本上是这样的:
- 得到的HTML文件的路径。
- 用html模板的内容创建一个字符串。
- 用我的字符串替换html中的标记(NSLocalized字符串 - 大量文本)。
- 使用“loadHTMLString”加载到新创建的字符串的WebView内容中。
结果:从70MB的内存占用,现在我有一个12MB的内存占用(和相当于约20页A4文本)。
下面的代码:
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"yourhtmlfile" ofType:@"html"];
NSURL *baseURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
[_webView setBackgroundColor:[UIColor clearColor]];
[_webView setOpaque:NO];
NSString *htmlBody = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF16StringEncoding error:nil];
htmlBody = [htmlBody stringByReplacingOccurrencesOfString:@"//marker_1//" withString:NSLocalizedString(@"localizedKey_1", nil)];
htmlBody = [htmlBody stringByReplacingOccurrencesOfString:@"//marker_2//" withString:NSLocalizedString(@"localizedKey_2", nil)];
htmlBody = [htmlBody stringByReplacingOccurrencesOfString:@"//marker_3//" withString:NSLocalizedString(@"localizedKey_3", nil)];
[self.webView loadHTMLString:htmlBody baseURL:baseURL];
现在我可以使用HTML的好东西像文本格式:d!
我希望以上会帮助很多人:)!
谢谢你们的支持!
['UITableView'](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableView_Class/Reference/Reference.html)有什么问题? – DrummerB
你是否暗示我应该使用UITableView? – Razvan
看看使用DTCoreText。它会渲染真正长的属性字符串,可能正是你所需要的。我在商店的应用程序中使用它。 –