我有一個NSMutableArray (_theListOfAllQuestions)
,我用一個文件中的數字填充。然後我將該陣列中的對象與qNr (NSString)
進行比較,發現錯誤。我甚至將陣列鑄造成另一個NSString
,_checkQuestions
,只是爲了確保我比較NSStrings
。我測試使用項目也比較。爲什麼我比較NSString的時候出錯? ( - [__ NSCFNumber isEqualToString:]:無法識別的選擇器發送到實例
-(void)read_A_Question:(NSString *)qNr {
NSLog(@"read_A_Question: %@", qNr);
int counter = 0;
for (NSString *item in _theListOfAllQuestions) {
NSLog(@"item: %@", item);
_checkQuestions = _theListOfAllQuestions[counter]; //_checkQuestion = NSString
NSLog(@"_checkQuestions: %@", _checkQuestions);
if ([_checkQuestions isEqualToString:qNr]) {
NSLog(@">>HIT<<");
exit(0); //Just for the testing
}
counter++;
}
運行此代碼我得到以下NSLog
:
read_A_Question: 421
item: 1193
_checkQuestions: 1193
...和錯誤:
-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x9246d80 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance 0x9246d80'
我相信我還是有一些比較一些NSString
排序,但對我來說,它看起來像我比較NSString
與NSString
?
我真的可以在這裏得到一些幫助1)理解問題,2)解決問題?
那好吧'_checkQuestions',至少在一種情況是'NSNumber',而不是'NSString' 。 '_theListOfAllQuestions'究竟是什麼?那是如何填充的? –