我正在使用UITableViewAutomaticDimension来计算行的高度。一切都很完美。 假设tableview中有100行 我面临的唯一问题是,当我调用scrollToRowAtIndexPath时,它会再次加载所有100个单元格。
我正在使用dequeueReusableCellWithIdentifier,但似乎在scrollToRowAtIndexPath时,它会再次加载所有100个单元格。
这是我的代码:
在ViewDidLoad中:
self.myTableView.estimatedRowHeight = EST_HEIGHT_CELL;
self.myTableView.rowHeight = UITableViewAutomaticDimension;
委托方法
- (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;
}
但是当我调用scrollToRowAtIndexPath时,它会加载所有单元格和tableview HANGS ......
dispatch_async(dispatch_get_main_queue(), ^{
[self.myTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:myIndex inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
});
我尝试过动画:没有,但仍然没有成功
如果我给heightForRowAtIndexPath赋予静态高度,scrollToRowAtIndexPath不会加载所有单元格,tableview也不会挂起,这是正常的,也是可以接受的。
可能是什么问题? 提前谢谢。