tableViewを呼び出しreloadDataても、コンテンツオフセットは変更されません。ただし、UITableViewAutomaticDimensioniOS 8で導入されたものを使用している場合は、問題が発生する可能性があります。
を使用している間UITableViewAutomaticDimension、デリゲートメソッドを記述して戻る必要がありtableView: estimatedHeightForRowAtIndexPath:ます。これも同じものを返します。UITableViewAutomaticDimensiontableView: heightForRowAtIndexPath:
私の場合、これを使用しているときにiOS8で問題が発生しました。を使用していても、メソッドestimatedHeightForRowAtIndexPath:メソッドが不正確な値を返していたためUITableViewAutomaticDimensionです。iOS 9デバイスには問題がなかったため、iOS8には問題がありました。
辞書を使用してセルの高さの値を格納し、それを返すことで、この問題を解決しました。これが私がしたことです。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSNumber *key = @(indexPath.row);
NSNumber *height = @(cell.frame.size.height);
[self.cellHeightsDictionary setObject:height forKey:key];
}
- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSNumber *key = @(indexPath.row);
NSNumber *height = [self.cellHeightsDictionary objectForKey:key];
if (height)
{
return height.doubleValue;
}
return UITableViewAutomaticDimension;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
高さが存在するかどうかのチェックは、ページが初めて読み込まれるときです。