I have some HTML data which I store it in CoreData as Binary Data
. I display it as NSMutableAttributedString
in UITableViewCells
as below:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSManagedObject *row = [self.messagesFRC objectAtIndexPath:indexPath];
MessageLTableViewCell *cell = (MessageLTableViewCell *)[self.tableView dequeueReusableCellWithIdentifier:@"MSGCELLID" forIndexPath:indexPath];
NSString *messageText = [[NSString alloc] initWithData:[row valueForKey:@"message_text"] encoding:NSUTF8StringEncoding];
messageText = [NSString stringWithFormat:@"<style>body{font-family: '%@';direction:rtl;float:right; font-size:%fpx;}</style>%@", FONT_TEXT, 17.0, messageText];
NSError *err = nil;
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc]
initWithData:[messageText dataUsingEncoding:NSUTF8StringEncoding]
options:
@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType,
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding),
}
documentAttributes: nil
error: &err];
if(err)
NSLog(@"Unable to parse label text: %@", err);
cell.messageText.attributedText = attrStr;
return cell;
}
The problem is that it causes high CPU load and also the UITableView
freezes in scrolling. What is the best practice solutions to handle it with best performance?