2011-09-04 118 views
0

我使用的核心數據有一個比較複雜的應用程序時,從管理對象消失,即除了在數據似乎消失了一個實例運作良好。我有一個託管對象類,pitLayer,有10個屬性(字符串和數字),一個視圖控制器(viewLayers),顯示屬於父對象的所有pitLayer對象,和一個視圖控制器(editLayer)可以編輯(和創建)新的坑層對象。價值觀傳遞給另一個視圖控制器

當我創建一個新的pitLayer,然後返回到表視圖,所有的屬性表中正確顯示。如果我立即回到editLayer,所有的值都顯示正確。

如果我然後用editLayer編輯另一個pitLayer,除了2,硬度和botttomHardness(兩個字符串)之外,我都可以得到正確的值,我仍然可以從前一個編輯好的pitLayer中獲取值。

如果我加載editLayer首次與現有pitLayer硬度和bottomHardness返回零,所有其他值返回先前存儲的值。

值越來越保存得當,它們可以在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

的值獲得存儲正確的,他們可以在 viewlayer中取回並返回co正確的值...

這表明值正在進入托管對象並保存到持久存儲區。

...但是,當它們在editLayer中被提取時,它們不會返回正確的 值。

對此的唯一解釋就是您將UI元素連接到錯誤的管理對象,錯誤的屬性或無對象。

調試,將需要看到的代碼。

相關問題