我有一個選擇器視圖控制器來選擇一個化學源和可能的濃度。如果來源不具有濃度,則只顯示一個選擇器。它由NSDictionary
填充,源類型名稱爲keys
,我製作的自定義模型對象Chemical
有四個屬性,兩個NSString
,1個float
和一個BOOL
。爲什麼不執行循環?
當我用包含2個組件的字典觸發此操作時,我想提取表示的Chemical
中的四個值。請注意,我使用前兩個屬性的值填充選取器,但不是float
或BOOL
。我在第一個組件中選中的鍵的數組中運行數組,並檢查第二個組件中的字符串與鍵/值數組中的每個Chemical
s的chemConcentration
屬性。當chemConcentration
匹配時,我知道我有正確的Chemical
,我可以獲取其屬性發回。
Whe!
問題是,即使我知道我到達for循環,它似乎被跳過。打印之前的NSLog
,但裏面的那個沒有。 sourceConstant
和sourceIsLiquid
住宿0.0
和NO
- (IBAction)selectedSourceButton {
NSLog(@"selectedSourceButton pressed");
NSInteger sourceRow = [picker selectedRowInComponent:kSourceComponent];
NSString *selectedSource = [self.sources objectAtIndex:sourceRow];
NSArray *selectedChemicalGroup = [dictionaryOfSources objectForKey:selectedSource];
NSInteger concentrationRow = [picker selectedRowInComponent:kConcentrationComponent];
NSString *selectedConcentration = [[NSString alloc] init];
float selectedConstant = 0.0;
BOOL selectedIsLiquid = NO;
if (numberOfComponents == 2) {
NSLog(@"numberOfComponents = 2 if/then chosen"); // <-- This prints.
selectedConcentration = [self.concentrations objectAtIndex:concentrationRow];
NSLog(@"begin selectedConcentration for loop. Number of loops = %d", [selectedChemicalGroup count]); // <-- And so does this.
for (int i; i<[selectedChemicalGroup count]; i++) { // <-- But this doesn't seem to fire!
NSLog(@"selectedConcentration = %@, from selectedChemicalGroup = %@", selectedConcentration, [[selectedChemicalGroup objectAtIndex:i] chemConcentration]); // <-- Because this doesn't print.
if ([selectedConcentration isEqualToString:[[selectedChemicalGroup objectAtIndex:i] chemConcentration]]) {
selectedConstant = [[selectedChemicalGroup objectAtIndex:i] chemConstant];
selectedIsLiquid = [[selectedChemicalGroup objectAtIndex:i] chemIsLiquid];
}
}
}
else {
selectedConcentration = @"";
selectedConstant = [[selectedChemicalGroup objectAtIndex:0] chemConstant];
selectedIsLiquid = [[selectedChemicalGroup objectAtIndex:0] chemIsLiquid];
}
NSLog(@"selectedSourceButton source to return = %@, concentration = %@, sourceConstant = %1.7f, isLiquid = %d", selectedSource, selectedConcentration, selectedConstant, selectedIsLiquid);
if ([self.delegate respondsToSelector:@selector (sourcePickerViewController:didSelectSource:andConcentration:andConstant:andIsLiquid:)]) {
[self.delegate sourcePickerViewController:self didSelectSource:selectedSource andConcentration:selectedConcentration andConstant:selectedConstant andIsLiquid:selectedIsLiquid];
}
}
+ for fast enumeration – Vladimir 2010-07-25 20:45:21