세 가지 구성 요소가있는 UIPickerView를 사용하여 응용 프로그램을 만들려고합니다. 첫 번째 구성 요소에는 3 개의 행이 있습니다. 두 번째 구성 요소에는 6 개의 행이 있고 세 번째 구성 요소에는 12 개의 행이 있습니다. 구성 요소 2 또는 3에서 행 3 이상으로 스크롤 할 때마다 응용 프로그램이 충돌하고 첫 번째 구성 요소 배열을 가리 킵니다. 나는 이것이 쉽게 고칠 수 있다고 확신하지만 나는 길을 잃는다. 미리 감사드립니다.여러 구성 요소가있는 UIPicker가 깨졌습니다.
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
{
NSString *resultString0 = [[NSString alloc] initWithFormat:
@"Sensor: %@",
[modelArray objectAtIndex:row]];
modelLabel.text = resultString0;
[resultString0 release];
}
{
NSString *resultString1 = [[NSString alloc] initWithFormat:
@"Pixels: %@",
[memoryArray objectAtIndex:row]];
memoryLabel.text = resultString1;
[resultString1 release];
NSString *firstString = horizFaceRecLabel.text;
float horizontalFace = [[horizontalArray objectAtIndex:row] floatValue];
float requiredFace = 100;
output1 = [firstString floatValue];
output1 = horizontalFace/requiredFace;
horizFaceRecLabel.text = [NSString stringWithFormat:(@"%.1f ft"), output1];
NSString *secondString = horizLicensePlateLabel.text;
float horizontalLicense = [[horizontalArray objectAtIndex:row] floatValue];
float requiredLicense = 45;
output2 = [secondString floatValue];
output2 = horizontalLicense/requiredLicense;
horizLicensePlateLabel.text = [NSString stringWithFormat:(@"%.1f ft"), output2];
NSString *thirdString = horizVisualIdLabel.text;
float horizontalVisual = [[horizontalArray objectAtIndex:row] floatValue];
float requiredVisual = 30;
output3 = [thirdString floatValue];
output3 = horizontalVisual/requiredVisual;
horizVisualIdLabel.text = [NSString stringWithFormat:(@"%.1f ft"), output3];
}
{
NSString *resultString2 = [[NSString alloc] initWithFormat:
@"Lens: %@",
[lensArray objectAtIndex:row]];
lensLabel.text = resultString2;
[resultString2 release];
{
NSString *firstDistString = faceRecLabel.text;
float angle = [[anglesArrayA objectAtIndex:row] floatValue];
float densityOne;
float densityTwo;
densityOne = [firstDistString floatValue];
densityTwo = (output1/2)/(sin(angle/2));
faceRecLabel.text = [NSString stringWithFormat:(@"%.1f ft"), densityTwo];
}
}
}
감사합니다. 안나, 실제로 원래 if 문을 사용했는데 실제로 작동하지만 괜찮 았지만 실제 코드가있는 구성 요소를 사용하지 않는 한 모든 필드를 업데이트하지는 않습니다. 예를 들어, 코드의 세 블록 사이에서 if 문을 사용할 때 firstString, secondString, thirdString은 구성 요소 1을 이동하지 않으면 업데이트되지 않습니다. 구성 요소를 이동하면 언제든지 업데이트를 수행합니까? – cbodbyl
현재 변경된 구성 요소에 관계없이 언제든지 호출 할 수있는'selectedRowInComponent' 메서드를 사용하여 모든 구성 요소에서 현재 선택된 행을 가져올 수 있습니다. 예 :'int currentRowInFirst = [pickerView selectedRowInComponent : 0];'. 구성 요소 별 코드를 if 문 내에 넣고 if 블록 외부에서 실행할 코드를 selectedRowInComponent를 사용하여 넣을 수 있습니다. 현재 컴퍼넌트 내에서 행이 선택되어 있지 않은 경우, 그 메소드는 -1을 돌려 주어, 배열을 인덱스하기 위해서 사용하기 전에 검사합니다. – Anna
빠른 추적 조사. if 문을 사용한 후 selectedRowInComponent 메서드를 사용했는데 원하는 방식으로 작동하는 것처럼 보입니다. 도와 줘서 고마워. – cbodbyl