title: Strange calls to modelIdentifierForElementAtIndexPath:inView: (UIDataSourceModelAssociation)
body: <p>I'm currently implementing automatic state preservation/restoration in an iOS6-only app.</p>
  
  <p>For a restoration of a table view, I added the <code>UIDataSourceModelAssociation</code> protocol to my table view controllers and implemented</p>
  
  <p><code>- (NSString *)modelIdentifierForElementAtIndexPath:(NSIndexPath *)idx inView:(UIView *)view</code></p>
  
  <p>and</p>
  
  <p><code>- (NSIndexPath *)indexPathForElementWithModelIdentifier:(NSString *)identifier inView:(UIView *)view</code></p>
  
  <p>When pressing the home button, the state preservation methods, including <code>modelIdentifierForElementAtIndexPath:iView:</code>, are getting called as expected and return valid identifier strings for the given index paths.</p>
  
  <p>When killing the app and relaunching it, state restoration works more or less. I.e. the app re-opens the correct table view. However, the table view is always scrolled to the top, even when it was scrolled to another position before.</p>
  
  <p>Here's the implementation of the <code>UIDataSourceModelAssociation</code> methods in my table view controller. Nothing fancy going on in there (the <code>NdlFriend::accountUid</code>property returns a unique identifier string for a given NdlFriend record):</p>
  
  <pre><code>#pragma mark - UIDataSourceModelAssociation
  - (NSString *)modelIdentifierForElementAtIndexPath:(NSIndexPath *)idx inView:(UIView *)view
  {
      NSString* identifier = nil;
      NSArray* content = self.contentArray;
  
      // Sometimes idx might be nil...
      if(idx &amp;&amp; idx.row&lt;content.count)
      {
          NdlFriend* friend = content[idx.row];
          identifier=friend.accountUid;
      }
      return identifier;
  }
  
  - (NSIndexPath *)indexPathForElementWithModelIdentifier:(NSString *)identifier inView:(UIView *)view
  {
      NSIndexPath * indexPath=nil;
      NSArray* content = self.contentArray;
      NSInteger count = content.count;
      for(NSInteger i=0;i&lt;count;i++)
      {
          NdlFriend* friend = content[i];
          if([identifier isEqualToString:friend.accountUid])
          {
              indexPath = [NSIndexPath indexPathForRow:i inSection:0];
              break;
          }
      }
      return indexPath;
  }
  </code></pre>
  
  <p>I set break points in both methods.</p>
  
  <p>To test the methods, I opened the table view and scrolled down a little bit. Then, when pressing the home button: </p>
  
  <ul>
  <li><code>modelIdentifierForElementAtIndexPath:inView:</code> gets called once, with the index path of the top most visible row. The method returns the correct uid for this row.</li>
  </ul>
  
  <p>So far so good.</p>
  
  <p>Then I stop and relaunch the app. Here's what happens (I'm especially puzzled by the first hit break point):</p>
  
  <ul>
  <li><code>modelIdentifierForElementAtIndexPath:inView:</code> gets called, with <code>nil</code> as index path (the view argument contains the correct pointer of the table view).</li>
  <li><code>indexPathForElementWithModelIdentifier:inView:</code> gets called with a valid identifier string (and a valid index path is returned by the method).</li>
  <li><code>indexPathForElementWithModelIdentifier:inView:</code> gets called again (with the same identifier string).</li>
  <li>The table view is refreshed, but scrolled to the very top.</li>
  </ul>
  
  <p>Does someone know, why the restoration of the scroll position fails? Does maybe the call of <code>modelIdentifierForElementAtIndexPath:inView:</code> with <code>nil</code> as indexPath has something to do with it (or is this normal behavior).</p>