我有一个选择器视图控制器,用于选择化学源和浓度。如果源中没有浓度,则仅显示一个选择器。它由一个源类型名称为NSDictionarykeys填充,我创建了一个名为Chemical的自定义模型对象,该对象具有四个属性,两个属性NSString,一个float和一个BOOL

当我用具有2个组成部分的字典触发此操作时,我想从表示的Chemical中提取四个值。请注意,我使用前两个属性的值填充选择器,但没有使用floatBOOL填充值。我在数组中查找在第一个组件中选择的键,并对照键/值数组中每个chemConcentrationChemical属性检查第二个组件的字符串。当chemConcentration匹配时,我知道我有正确的Chemical,并且可以获取其属性以发回。

ew!

问题是,即使我知道我进入了for循环,它似乎也被跳过了。 NSLog就在它打印之前,但是里面没有。 sourceConstantsourceIsLiquid保持0.0NO

- (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 (int i = 0; i<[selectedChemicalGroup count]; i++)

09-25 23:57