gpt4 book ai didi

ios - 带有 UI 对象的 NSArray(性能)

转载 作者:行者123 更新时间:2023-11-29 02:14:59 24 4
gpt4 key购买 nike

我有一个 NSArray(实际上是一个可变数组),每个索引中都有一个 UIWebView 对象。我使用此数组填充 UITableView 中的单元格。我使用 for 循环来初始化数组中的每个对象,如下所示:

for (int i = 0; i < [self.events count]; i++) {

[self.uiWebViewArray addObject:[[UIWebView alloc] init]];
[[self.uiWebViewArray objectAtIndex:i] setUserInteractionEnabled:NO];
[[self.uiWebViewArray objectAtIndex:i] loadHTMLString:HTMLContent baseURL:nil];
}

此时我还没有填充 UITableViewCells

虽然它有效,但我认为这是一种糟糕的方法。当我增加单元格数量时,性能会下降。在某些时候,用户可能会注意到延迟。

我还尝试用 UIWebView 直接填充每个单元格,但这基本上是一样的。

有没有人建议以有效的方式解决用 UIWebView 对象填充 UITableViewCell 的问题?

非常感谢任何帮助。

最佳答案

问题不在于数组,而在于 webview 速度非常慢且占用大量内存。
如果您想使用基本 CSS 显示 HTML 文本并且您正在部署 >= iOS7,则应该使用 NSAttributeString 和该方法:

NSDictionary *importParams = @{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding) };
NSError *error = nil;
NSData *stringData = [HTML dataUsingEncoding:NSUTF8StringEncoding] ;
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:stringData options:importParams documentAttributes:NULL error:&error];

或者您可以使用第三方库 DTCoreText就是其中之一。

关于ios - 带有 UI 对象的 NSArray(性能),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28856831/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com