環境:Xcode的7.2,構建版本7C68,Objective-C的NSInternalInconsistencyException在UICollectionViewController在Xcode 7.2/Objective-C的
在我的應用我有一個UIViewController,名爲GameView,包含UICollectionViewController,名爲「questionCollectionViewController 「,其中有一個名爲」gameQuestions「的NSMutableArray,因爲它是數據源。 GameView有一個「重置遊戲」按鈕,可以執行一個展開式遊戲。前展開SEGUE執行我可以看到UICollectionViewController位於0x7a79e810和的NSMutableArray位於0x7b936bd0:
(lldb) print self.questionCollectionViewController
(QuestionCollectionViewController *) $0 = 0x7a79e810
(lldb) print self.questionCollectionViewController.gameQuestions
(__NSArrayM *) $1 = 0x7b936bd0 @"38 objects"
退繞SEGUE之前,我清除經由的NSMutableArray removeAllObjects的gameQuestions陣列()方法:
-(void) resetGameState {
[[self.questionCollectionViewController gameQuestions] removeAllObjects];
}
開卷SEGUE後,當我重新演繹到的UIViewController我得到的UICollectionViewController的一個新實例,實例化SEGUE /填充新的NSMutableArray:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if([[segue identifier] isEqualToString:@"QuestionCollectionSegue"]) {
self.questionCollectionViewController = [segue destinationViewController];
[self.questionCollectionViewController setGameQuestions:[[self game] copyGameQuestions]];
}
}
在此之後我可以看到UICollectionViewController現在位於0x7a700e30和NSMutableArray裏現在是0x7a60a4a0:
(lldb) print self.questionCollectionViewController
(QuestionCollectionViewController *) $2 = 0x7a700e30
(lldb) print self.questionCollectionViewController.gameQuestions
(__NSArrayM *) $3 = 0x7a60a4a0 @"40 objects"
當我選擇一個問題,通過。該didSelectItemAtIndexPath委託方法,didSelectItemAtIndexPath完成執行後,我能看到的CollectionView和NSMutableArray中仍處於新地址:
(lldb) print self
(QuestionCollectionViewController *) $4 = 0x7a700e30
(lldb) print self.gameQuestions
(__NSArrayM *) $5 = 0x7a60a4a0 @"40 objects"
由於地址都很好didSelectItemAtIndexPath完成後,我沒有看到一個問題didSelectItemAtIndexPath。但是,一旦我點擊這個問題的的UITextField,突然的和的CollectionView現在的NSMutableArray的非之前恢復到了在開卷SEGUE清除原始地址/對象,在0x7a79e810和0x7b936bd0,進行風賽格瑞和前的NSMutableArray被清除,並重新實例:
(lldb) print self
(QuestionCollectionViewController *) $6 = 0x7a79e810
(lldb) print self.gameQuestions
(__NSArrayM *) $7 = 0x7b936bd0 @"0 objects"
這會導致應用程序與NSInternalInconsistencyException崩潰,因爲顯示的CollectionView有40個對象,但現在它的數據源現在已經莫名其妙地被收歸到舊的清除NSMutableArray。
我在UIKeyboardDidShowNotification上訂閱了通知,並且地址已經在這一點上改變了。我UITextFieldDelegates樣子:
# 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];
}
沒有任何人有任何想法可能是導致UICollectionViewController要恢復到自己的一箇舊實例,它是某種方式仍然被保留在內存中?