みなさんの助けを借りて、私はこのソリューションを思いつきました。
内部にマーカーを含むhtml「テンプレート」ファイルとUIWebViewを使用しています。
基本的に私がやっていることは次のとおりです。
- html ファイルのパスを取得します。
- html テンプレートの内容で文字列を作成します。
- html のマーカーを自分の文字列 (NSLocalized 文字列 - 大量のテキスト) に置き換えます。
- 「loadHTMLString」を使用して、新しく作成された文字列の WebView コンテンツにロードします。
結果: 70MB のメモリ フットプリントから、12MB のメモリ フットプリントが得られました (これは A4 のテキストの約 20 ページに相当します)。
コードは次のとおりです。
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!
上記が多くの人に役立つことを願っています:)!
応援ありがとうございました!