필자는 화학 소스와 농도를 선택할 수있는 선택기 뷰 컨트롤러를 가지고 있습니다. 소스에 농도가 없으면 단일 피커가 나타납니다. 소스 형식 이름이 NSDictionary
이고 채우기 유형이 keys
이고 사용자 지정 모델 개체가 Chemical
이고 두 속성이 NSString
이고 하나가 float
이고 하나가 BOOL
인 채우는 사용자 지정 모델 개체로 채워집니다.this for for 루프가 실행되지 않는 이유는 무엇입니까?
두 개의 구성 요소가있는 사전을 사용하여이를 트리거하면 표현 된 Chemical
에서 네 개의 값을 추출하고 싶습니다. 피커에 처음 두 속성의 값을 채우지 만 float
또는 BOOL
이 아닌 값을 채 웁니다. 첫 번째 구성 요소에서 선택된 키에 대한 배열을 실행하고 키/값 배열의 Chemical
각각의 chemConcentration
속성에 대해 두 번째 구성 요소의 문자열을 확인합니다. chemConcentration
이 일치하면 Chemical
의 권리가 있으며 다시 보낼 속성을 얻을 수 있음을 알고 있습니다.
휴!
문제는 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];
}
}
+ 빠른 열거 형 – Vladimir