I am using UITableViewAutomaticDimension for calculating height of rows. Everything is working perfectly. Let say there are 100 rows in tableview The only issue i am facing is that when i call scrollToRowAtIndexPath, it loads all 100 cells again.
I am using dequeueReusableCellWithIdentifier but it seems when scrollToRowAtIndexPath, it loads all 100 cells again.
Here is my code:
In ViewDidLoad:
self.myTableView.estimatedRowHeight = EST_HEIGHT_CELL;
self.myTableView.rowHeight = UITableViewAutomaticDimension;
The delegate methods
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(7_0) {
return EST_HEIGHT_CELL;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString * resuseID = @“MyCell”;
MyCell * cell = [tableView dequeueReusableCellWithIdentifier:resuseID];
if(!cell) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"MyCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.cellIndex = indexPath;
cell.myDelegate = self;
return cell;
}
But when i call scrollToRowAtIndexPath, it loads all cells and the tableview HANGS...
dispatch_async(dispatch_get_main_queue(), ^{
[self.myTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:myIndex inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});
I have tried with animated:NO but still no success
If i give static height to heightForRowAtIndexPath, scrollToRowAtIndexPath doesn't load all the cells and tableview does not hangs, which is normal and acceptable.
What can be the issue? Thanks in advance.