這裏是我的循環For循環退出過早
-(void)analyzeDataWithSearchTerm:(NSString *)searchTerm {
[searchResults removeAllObjects];
NSLog(@"number of items = %i", [itemIDRows count]);
for (int i = 0; i < [itemIDRows count]; i++) {
bool foundResult = FALSE;
if ([[[itemIDRows objectAtIndex:i] lowercaseString] rangeOfString:[searchTerm lowercaseString]].location != NSNotFound) {
NSLog(@"ID matches %@", [itemIDRows objectAtIndex:i]);
foundResult = TRUE;
}
if ([[[itemNameRows objectAtIndex:i] lowercaseString] rangeOfString:[searchTerm lowercaseString]].location != NSNotFound) {
NSLog(@"name Matches %@", [itemNameRows objectAtIndex:i]);
foundResult = TRUE;
}
if ([[[barcodeRows objectAtIndex:i] lowercaseString] rangeOfString:[searchTerm lowercaseString]].location != NSNotFound) {
NSLog(@"barcode Matches %@", [barcodeRows objectAtIndex:i]);
foundResult = TRUE;
}
if ([aliasRows objectAtIndex:i] != [NSNull null]) {
if ([[[aliasRows objectAtIndex:i] lowercaseString] rangeOfString:[searchTerm lowercaseString]].location != NSNotFound) {
NSLog(@"alias Matches %@", [aliasRows objectAtIndex:i]);
foundResult = TRUE;
}
}
if (foundResult) {
NSNumber *result = [NSNumber numberWithInt:i];
NSLog(@"found result");
[searchResults addObject:result];
} else {
NSLog(@"no result was found this time");
}
}
if (isScanning) {
//do something different
}
}
這個問題似乎是,如果我設置了「isScanning」爲真(這是一個布爾)發生和運行的方法「analyzeDataWithSearchTerm」第二次。
基本上這個循環檢查項目是否已經在採購訂單中。如果不是,則提供要添加的項目。下次掃描物品時,循環運行並通過,並應檢測物品處於採購訂單中。我已經設置了斷點,但第二次循環運行時(只有2個項目在順序中)找到一個結果,進入foundResult = TRUE
行,沒有將bool設置爲true,並且整個方法停止。它甚至從來沒有使它對
if (foundResult) { }
任何想法,爲什麼這可能發生?
該應用程序是否錯誤並退出或繼續運行? – BWC
它一直運行得很好......只是這種方法在沒有實際完成的情況下退出。 – Hackmodford
哪個「foundResult = TRUE」是這種情況?在ifScanning塊內發生了什麼?第一個是 – Rayfleck