title: TableView jumps on top after reloading data. I tried some solutions that I found here, but none of it worked. Please check the description
body: <p>I am making a chat page, where I scroll on top, I reload the previous message from API. After getting response, reload the table, and the table moves to first cell. But I want it to be stay where it was during loading the messages. Following are the solutions that I tried:</p>
  
  <p><strong>Solution 1:</strong>
  Declared this:
  <code>NSMutableDictionary *cellHeightsDictionary;</code></p>
  
  <p>Added this in viewDidLoad:</p>
  
  <pre><code>    self.chatTableView.rowHeight = UITableViewAutomaticDimension;
      cellHeightsDictionary = @{}.mutableCopy;
  </code></pre>
  
  <p>Then added the below mentioned methods:</p>
  
  <pre><code>// save height
  - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
      [cellHeightsDictionary setObject:@(cell.frame.size.height) forKey:indexPath];
  }
  
  
  // give exact height value
  - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
      NSNumber *height = [cellHeightsDictionary objectForKey:indexPath];
      if (height) return height.doubleValue;
      return UITableViewAutomaticDimension;
  }
  
   - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
      return UITableViewAutomaticDimension;
  }
  
  </code></pre>
  
  <p>And here reloading my tableview:</p>
  
  <pre><code>- (void)reloadAllMessagesHere {
      [UIView performWithoutAnimation:^{
          [self.chatTableView reloadData];
          [self.chatTableView beginUpdates];
          [self.chatTableView endUpdates];
      }];
  }
  </code></pre>
  
  <p><strong><em>But still the same issue is happening.</em></strong></p>
  
  <p>Then I thought I should use the bottom contentOffset of the page. So, I used this method to reload the data:</p>
  
  <p><strong>Solution 2:</strong>
  Removed all above codes and used these methods:
  For TableView Height:</p>
  
  <pre><code> - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
      return UITableViewAutomaticDimension;
  }
  </code></pre>
  
  <p>and tableview reload</p>
  
  <pre><code>- (void)reloadWithoutMoving {
      CGPoint contentOffsetVal = CGPointMake(0, self.chatTableView.contentSize.height - self.chatTableView.bounds.size.height);
      [self.chatTableView reloadData];
      [self.chatTableView layoutIfNeeded];
      [self.chatTableView setContentOffset:contentOffsetVal];
  }
  </code></pre>
  
  <p><strong>BUT NO LUCK!!</strong></p>
  
  <p>Here check the two images shown below:</p>
  
  <p><strong>Image 1:</strong> Here I am loading the tableview.</p>
  
  <p><strong>Image 2:</strong> Here I got the response and the data shown in <em>Image 1</em> move to bottom automatically</p>
  
  <p><a href="https://i.stack.imgur.com/6osCa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6osCa.jpg" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/vsV1T.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vsV1T.jpg" alt="enter image description here"></a></p>
  
  <p>How can I fix this?</p>
  
  <p>[P.S. Please don't mark this as duplicate as I have tried previous the solutions but couldn't fix it.]</p>