UITableView self sizing cell scrolling issues with big difference of cell height
Asked Answered
S

2

8
  func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell{

    let json = JSON(data: activityTableView.onlineFeedsData)[indexPath.row] // new
    if(json["topic"]["reply_count"].int > 0){
        if let cell: FeedQuestionAnswerTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier_reply) as? FeedQuestionAnswerTableViewCell{

            cell.selectionStyle = .None
            cell.tag = indexPath.row
            cell.relatedTableView = self.activityTableView
            cell.configureFeedWithReplyCell(cell, indexPath: indexPath, rect: view.frame,key: "activityTableView")
            // Make sure the constraints have been added to this cell, since it may have just been created from scratch
            cell.layer.shouldRasterize = true
            cell.layer.rasterizationScale = UIScreen.mainScreen().scale

            return cell
        }
    }else{
        if let cell: FeedQuestionTableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as? FeedQuestionTableViewCell{

            cell.selectionStyle = .None
            cell.tag = indexPath.row
            cell.relatedTableView = self.activityTableView
            cell.configureFeedCell(cell, indexPath: indexPath, rect: view.frame)
            // Make sure the constraints have been added to this cell, since it may have just been created from scratch

            cell.layer.shouldRasterize = true
            cell.layer.rasterizationScale = UIScreen.mainScreen().scale
            return cell
        }
    }


    return UITableViewCell()
}

There is difference of 200-400 in height in each cell,So tried implementing the height calculation in estimatedHeightForRowAtIndexPath .I cant the exact estimate height in this method as bcz of calculation

and caching the height in willDisplayCell method but still the scroll jumps like is it taking time to rendering .

The cell is like the Facebook card type layout with lots of dynamic data with variable height text and images.Can someone help me in this .Thanks

Scream answered 10/2, 2016 at 6:43 Comment(1)
Can you tell me more about how to calculate the height of the cell in tableView(_:estimatedHeightForRowAtIndexPath:)?Laliberte
E
0

If you're able to calculate each cells height, just use the tableView(_:heightForRowAtIndexPath) instead of estimatedRowHeightAtIndexPath property. estimatedRowHeightAtIndexPath is mostly used in smthg like selfsizing cells etc.

Exo answered 6/3, 2016 at 19:4 Comment(1)
NSMutableDictionary *cellHeightsDictionary; // initialize in code cellHeightsDictionary = @{}.mutableCopy;Pooch
P
0

Try this one. I hope this could help you. It's worked for me. Actually this calculates the cell height before it displayed. Thanks.

NSMutableDictionary *cellHeightsDictionary;

// Put this in viewDidLoad

cellHeightsDictionary = @{}.mutableCopy;

// UITableview delegate Methods

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
NS_AVAILABLE_IOS(7_0)
{
    NSNumber *height = [cellHeightsDictionary objectForKey:indexPath];
    if (height) return height.doubleValue;
    return UITableViewAutomaticDimension;
}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cellHeightsDictionary setObject:@(cell.frame.size.height) forKey:indexPath];

}
Pooch answered 12/1, 2017 at 7:4 Comment(1)
thnks @yogesh i will definetly try , but i ended up removing autolayout and code it in frame based using AsyncdisplayKit to acheive ma requirementsScream

© 2022 - 2024 — McMap. All rights reserved.