2011-09-04 3 views
0

데이터가 사라지는 것처럼 보이는 한 인스턴스를 제외하고는 코어 데이터를 사용하는 다소 복잡한 응용 프로그램이 있습니다.다른보기 컨트롤러에 전달할 때 관리 개체에서 값이 사라짐

10 개의 속성 (문자열 및 숫자), 부모 객체에 속한 모든 pitLayer 객체를 표시하는보기 컨트롤러 (viewLayers) 및 뷰 컨트롤러 (editLayer)가있는 관리 객체 클래스 pitLayer가 있습니다. 새로운 피트 레이어 객체를 편집 (및 생성) 할 수 있습니다.

새 pitLayer를 만든 다음 다시 테이블보기로 돌아 오면 모든 속성이 테이블에 올바르게 표시됩니다. editLayer로 바로 돌아 가면 모든 값이 올바르게 표시됩니다.

editLayer를 사용하여 다른 pitLayer를 편집하는 경우 2, 경도 및 botttomHardness (두 문자열)를 제외한 모든 속성에 대해 올바른 값을 얻습니다. 편집 된 이전 pitLayer에서 값을 가져옵니다.

기존 pitLayer 경도 및 bottomHardness가 nil 인 editLayer를 처음으로로드하면 다른 모든 값은 이전에 저장된 값을 반환합니다.

값이 제대로 저장되고 viewLayers에서 가져 와서 올바른 값을 반환 할 수 있지만 editLayer에서 가져올 때 올바른 값을 반환하지 않습니다. 그리고 그것은 속성의 단지 2입니다, 다른 8 잘 작동하는 것.

디버깅에 대한 제안 사항이 있으십니까?

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ if(component == kGrainTypeComponent){ layer.grainType = [[grainTypeValues objectAtIndex:row] valueForKey:@"code"]; }else if(component == kSecondGrainTypeComponent){ layer.secondGrainType = [[grainTypeValues objectAtIndex:row] valueForKey:@"code"]; } else if(component == kHardnessComponent){ layer.hardness = [[hardnessValues objectAtIndex:row] valueForKey:@"code"]; } else if(component == kSecondHardnessComponent){ layer.bottomHardness = [[hardnessValues objectAtIndex:row] valueForKey:@"code"]; } [self checkSavable]; }

을 그리고 여기가 나중에 검색 취득에 실패 곳이다 : 여기

들은 설정 얻을된다

-(void)resetDefaults{ 
if(edit == YES && layer != nil){//Edit an existing layer 
    if(layer.comments) 
     comments.text = layer.comments; 
    else 
     comments.text = @""; 
    if(layer.thickness){ 
     thicknessSlider.value = [layer.thickness floatValue]; 
     [self thicknessChanged]; 
    } 
    if(layer.grainSize){ 
     grainSizeSlider.value = [layer.grainSize floatValue]; 
     [self grainSizeChanged]; 
    }else{ 
     grainSizeSlider.value = 0; 
     grainSizeLabel.text = @""; 
    } 
    if(layer.density){ 
     densitySlider.value = [layer.density floatValue]; 
     [self densityChanged]; 
    }else{ 
     densitySlider.value = 0; 
     densityLabel.text = @""; 
    } 
    NSString *type = layer.grainType; 
    NSString *secondType = layer.secondGrainType; 
    NSString *hardness = nil; 
    hardness = layer.hardness; 
    NSString *bottomHardness = nil; 
    bottomHardness = layer.bottomHardness; 
    NSString *lwc = layer.liquidWaterContent; 
    NSUInteger typeIndex = 0; 
    NSUInteger secondTypeIndex = 0; 
    NSUInteger hardnessIndex = 0; 
    NSUInteger bottomHardnessIndex = 0; 
    NSLog(@"type:%@, hardness: %@, bottom hardness: %@", type, hardness, bottomHardness); 
    if(type){ 
     for(int i = 0; i < [grainTypeValues count]; i++){ 
      if([[[grainTypeValues objectAtIndex:i] valueForKey:@"code"] isEqualToString: type]){ 
       typeIndex = i; 
       break; 
      } 
     } 
    } 
    [picker selectRow:typeIndex inComponent:kGrainTypeComponent animated:NO]; 
    if(secondType){ 
     for(int i = 0; i < [grainTypeValues count]; i++){ 
      if([[[grainTypeValues objectAtIndex:i] valueForKey:@"code"] isEqualToString:secondType]){ 
       secondTypeIndex = i; 
       break; 
      } 
     } 
    } 
    [picker selectRow:secondTypeIndex inComponent:kSecondGrainTypeComponent animated:NO]; 
    if(hardness){ 
     for(int i = 0; i < [hardnessValues count]; i++){ 
      if([[[hardnessValues objectAtIndex:i] valueForKey:@"code"] isEqualToString:hardness]){ 
       hardnessIndex = i; 
       break; 
      } 
     } 
    } 
    [picker selectRow:hardnessIndex inComponent:kHardnessComponent animated:NO]; 
    if(bottomHardness){ 
     for(int i = 0; i < [hardnessValues count]; i++){ 
      if([[[hardnessValues objectAtIndex:i] valueForKey:@"code"] isEqualToString:bottomHardness]){ 
       bottomHardnessIndex = i; 
       break; 
      } 
     } 
    } 
    if(secondHardness) 
     [picker selectRow:bottomHardnessIndex inComponent:kSecondHardnessComponent animated:NO]; 
    if(lwc){ 
     for(int i = 0; i < [lwcValues count]; i++){ 
      if([[[lwcValues objectAtIndex:i] valueForKey:@"code"] isEqualToString:lwc]){ 
       lwcSlider.value = [[[lwcValues objectAtIndex:i] valueForKey:@"value"] floatValue]; 
       lwcLabel.text = [[lwcValues objectAtIndex:i] valueForKey:@"name"]; 
       break; 
      } 
     } 
    }else{ 
     lwcSlider.value = 0; 
     lwcLabel.text = @""; 
    } 
    if(layer.formationDate){ 
     datePicker.date = layer.formationDate; 
     [self dateChanged]; 
    }else{ 
     formationDate.text = @""; 
     datePicker.date = [NSDate date]; 
    } 

}else{//create a new layer 
    comments.text = @""; 
    thicknessSlider.value = 0; 
    thicknessLabel.text = @"0.0"; 
    grainSizeSlider.value = 0; 
    grainSizeLabel.text = @""; 
    densityLabel.text = @""; 
    densitySlider.value = 0; 
    lwcLabel.text = @""; 
    lwcSlider.value = 0; 
    formationDate.text = @""; 
    datePicker.date = [NSDate date]; 
    [picker selectRow:0 inComponent:kGrainTypeComponent animated:NO]; 
    [picker selectRow:0 inComponent:kSecondGrainTypeComponent animated:NO];  
    [picker selectRow:0 inComponent:kHardnessComponent animated:NO]; 
    if(secondHardness) 
     [picker selectRow:0 inComponent:kSecondHardnessComponent animated:NO]; 
} 
thicknessUnitLabel.text = layer.parentPit.depthUnit; 
locationUnitLabel.text = layer.parentPit.depthUnit; 
densityUnitLabel.text = layer.parentPit.densityUnit; 
if([layer.parentPit.densityUnit isEqualToString:@"kg/m3"]){ 
    densitySlider.maximumValue = 1000; 
    densitySliderDecimalCutoff = 0; 
}else{ 
    densitySlider.maximumValue = 100; 
    densitySliderDecimalCutoff = 20; 
} 
topLabel.text = [NSString stringWithFormat:@"%1.1F", [[layer topLocation] floatValue]]; 
bottomLabel.text = [NSString stringWithFormat:@"%1.1F", [[layer bottomLocation] floatValue]]; 

가}

+0

editLayer에 대한 코드 추가 - 뭔가 문제가있는 것 같습니다. :) – deanWombourne

답변

0

값이 저장 얻고있다 올바르게, 그리고 그들은 viewLayers에서 가져올 수 있으며, 공동으로 반환합니다. 직전 값 ...

이는 값이 관리 객체에 들어가고 영구 저장소에 저장되고 있음을 나타냅니다.

...하지만 editLayer에서 가져 오면 올바른 값을 반환하지 않습니다.

정말 유일한 설명은 UI 요소를 잘못된 관리 대상, 잘못된 특성 또는 nil 개체에 연결 한 것입니다.

코드를 볼 필요가있는 디버깅.

관련 문제