我在单元格中有一个 UITableView
和 UIWebView
。
我要显示的数据是从网络上获取的,存储在数组中,然后通过 UIWebView
显示。我必须使用 WebView
,因为我有一些 MathJax 只能通过它来显示。
当我在 UITableView
中滚动时,在 WebView
正在加载 HTML 的一瞬间性能不佳。。 p>
有什么办法可以解决这个问题吗?
我想到的是某种预填充 webViews
,但我不确定这是否可行。我在网上没有找到任何有用的东西。
有什么想法吗?
编辑:
我之前没有添加代码,因为这是一个普遍的问题,任何带有UIWebView
的UITabelView
都会有这个性能问题。但这里是:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
SuperTraenerHistoryCell *cell = (SuperTraenerHistoryCell*)[tableView
dequeueReusableCellWithIdentifier:@"SuperTraenerHistoryCell"];
if (cell == nil){
NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"SuperTraenerHistoryCell" owner:self
options:nil];
cell = [nib objectAtIndex:0];
}
[cell.answer loadHTMLString:myAnswer.answer_text baseURL:[NSURL URLWithString:NSTemporaryDirectory()]];
}
SuperTraenerHistoryCell.h
@interface SuperTraenerHistoryCell : UITableViewCell
@property (strong, nonatomic) IBOutlet UIWebView *_answer;
@property (strong, nonatomic) IBOutlet UIImageView *correct;
@end
在 webView 中我显示数据,在 UIImageView
中我显示绿色或红色标志,如果问题回答正确或错误。
最佳答案
我想你的单元格的 answer
属性是一个 WebView
,这显然不是在 tableviewcell 中显示信息的最有效方式,因为加载内容是异步的。
如果是这样,因为您的内容似乎在您的应用程序中处于离线状态,请尝试考虑使用 NSAttributedText 显示格式化文本或将您的内容拆分为 UIImageView
和 UILabel
显示速度更快。
反正信息这么少,很难帮到你。也许如果您编辑您的帖子并添加您的 SuperTraenerHistoryCell
标题,在这里可能真的很有帮助。
关于ios - 单元格中带有 UIWebView 的 UITableView 性能不佳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26035008/