-4

It takes too much time on [_fetchedResultsController objectAtIndexPath:indexPath], is there any alternative way ? heightForRowAtIndexPath takes too much time on this point. I don't know this is wrong question or not, but please help me to get the proper solution.

   - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath   *)indexPath
 {
    ThreadInfo *info=[_fetchedResultsController objectAtIndexPath:indexPath];
    NSString* objectId = info.threadID;
    if (![self.idToCellHeight objectForKey: objectId])
    {
        CGFloat height = [self calculateHeightForId:info];
        [self.idToCellHeight setObject:[NSNumber numberWithFloat:height] forKey: objectId];
    }
    return [[self.idToCellHeight objectForKey:objectId] floatValue];

}
Jan
  • 1,744
  • 3
  • 23
  • 38

2 Answers2

0

Have you run Instruments? Run the Time Profiler. What is taking up the time? Find it and eliminate it.

If you can't find it, post the trace here for others to look at it.

Marcus S. Zarra
  • 46,571
  • 9
  • 101
  • 182
0

The alternative way is to use self-sizing cells. You won't have to calculate (or cache) any row heights.

  1. Add Auto Layout constraints to your tableViewCell's subviews which will cause the cell to adjust its height based on the subview's contents.
  2. Enable row height estimation.

    self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.estimatedRowHeight = 44.0;

For more information, see the detailed walkthrough by smileyborg in his answer to Using Auto Layout in UITableView for dynamic cell layouts & variable row heights.

Community
  • 1
  • 1