title: NSInternalInconsistencyException in UICollectionViewController in Xcode 7.2/Objective-C
body: <p><strong>Environment</strong>: Xcode 7.2, Build version 7C68, Objective-C</p>
  
  <p>In my application I have a UIViewController, named GameView, that contains a UICollectionViewController, named "questionCollectionViewController", with an NSMutableArray called "gameQuestions" as it's datasource. The GameView has a "reset game" button that performs an unwind seque. Before the unwind segue is performed I can see the UICollectionViewController is located at <strong>0x7a79e810</strong> and the NSMutableArray is located at <strong>0x7b936bd0</strong>:</p>
  
  <pre><code>(lldb) print self.questionCollectionViewController
  (QuestionCollectionViewController *) $0 = 0x7a79e810
  
  (lldb) print self.questionCollectionViewController.gameQuestions
  (__NSArrayM *) $1 = 0x7b936bd0 @"38 objects"
  </code></pre>
  
  <p>Before the unwind segue, I clear the gameQuestions array via the NSMutableArray removeAllObjects() method:</p>
  
  <pre><code>-(void) resetGameState {
      [[self.questionCollectionViewController gameQuestions] removeAllObjects];
  }
  </code></pre>
  
  <p>After the unwind segue, when I re-perform the segue to the UIViewController  I get a new instance of the UICollectionViewController and instantiate/populate a new NSMutableArray:</p>
  
  <pre><code>- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
      if( [[segue identifier] isEqualToString:@"QuestionCollectionSegue"] ) {
          self.questionCollectionViewController = [segue destinationViewController];
          [self.questionCollectionViewController setGameQuestions:[[self game] copyGameQuestions]];
      }
  }
  </code></pre>
  
  <p>After this I can see the UICollectionViewController is now located at <strong>0x7a700e30</strong> and the NSMutableArray is now at <strong>0x7a60a4a0</strong>:</p>
  
  <pre><code>(lldb) print self.questionCollectionViewController
  (QuestionCollectionViewController *) $2 = 0x7a700e30
  
  (lldb) print self.questionCollectionViewController.gameQuestions
  (__NSArrayM *) $3 = 0x7a60a4a0 @"40 objects"
  </code></pre>
  
  <p>When I select a question, via. the didSelectItemAtIndexPath delegate method, after didSelectItemAtIndexPath completes execution I can see the CollectionView and NSMutableArray are still at the new addresses:</p>
  
  <pre><code>(lldb) print self
  (QuestionCollectionViewController *) $4 = 0x7a700e30
  
  (lldb) print self.gameQuestions
  (__NSArrayM *) $5 = 0x7a60a4a0 @"40 objects"
  </code></pre>
  
  <p>Since the address are fine after didSelectItemAtIndexPath completes, I do not see a problem with didSelectItemAtIndexPath. However, once I click the UITextField of the question, all of a sudden the CollectionView and NSMutableArray now revert to the original addresses/objects that were cleared in the unwind segue, at <strong>0x7a79e810</strong> and <strong>0x7b936bd0</strong>, <strong>before</strong> the un-wind segue was performed and <strong>before</strong> the NSMutableArray was cleared and re-instantiated:</p>
  
  <pre><code>(lldb) print self
  (QuestionCollectionViewController *) $6 = 0x7a79e810
  
  (lldb) print self.gameQuestions
  (__NSArrayM *) $7 = 0x7b936bd0 @"0 objects"
  </code></pre>
  
  <p>This causes the app to crash with an NSInternalInconsistencyException because the displayed CollectionView has the 40 objects but now it's datasource has now somehow been reverted to the old cleared NSMutableArray.</p>
  
  <p>I subscribed for notifications on UIKeyboardDidShowNotification and the address have already changed by this point. My UITextFieldDelegates look like:</p>
  
  <pre><code># pragma mark - UITextFieldDelegate
  -(BOOL) textFieldShouldReturn:(UITextField *)textField {
      [textField resignFirstResponder];
      return TRUE;
  }
  
  - (void) textFieldDidBeginEditing:(UITextField *)textField {
      [self enableSubmitButton:TRUE];
      [[self QVAnswerTextField] setPlaceholder: @""];
  }
  
  - (void) textFieldDidEndEditing:(UITextField *)textField {
      [self checkValidAnswer];
  }
  </code></pre>
  
  <p>Does anybody have any idea what could be causing the UICollectionViewController to be reverting to an old instance of itself that is somehow still being retained in memory?</p>