2010-11-29 78 views
1

所以我在我的視圖出現時從.plist訪問一些數據(設置)。當我使用viewDidAppear:(BOOL)animated方法來訪問這些數據時,所有的工作都很好,很棒。但是當我使用viewWillAppear:(BOOL)animated方法訪問數據來訪問我的數據時,一切都停止了,並且出現EXC_BAD_ACCESS錯誤。當使用viewWillAppear時,我得到一個EXC_BAD_ACCESS:(BOOL)動畫方法

有人可以幫我解決這個問題嗎?

- (void)viewDidAppear:(BOOL)animated { 

    NSLog(@"View Will Appear method"); 

    NSString *filePath = [self settingsFilePath]; 
    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) { 

     NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath]; 

     if ([[array objectAtIndex:0] intValue] == 0) { 
      UIImage *imageLow = [UIImage imageNamed:@"image1.png"]; 
      [object1 setImage:imageLow]; 
      [imageLow release]; 
      unitRatio = 1.8; 
     } 
     else if ([[array objectAtIndex:0] intValue] == 1) { 
      UIImage *imageHigh = [UIImage imageNamed:@"image2.png"]; 
      [object1 setImage:imageHigh]; 
      [imageHigh release]; 
      unitRatio = 0.9; 
     } 

     [array release]; 

    } 
    else { 
     UIImage *imageLow = [UIImage imageNamed:@"image1.png"]; 
     [object1 setImage:imageLow]; 
     [imageLow release]; 
     unitRatio = 1.8; 
    } 

} 
+0

你可以發佈我們的代碼嗎?這是第一次出現視圖時的情況嗎?或只有當你切換回它? – MCannon 2010-11-29 00:41:31

+0

當我切換回它...我想這可能與釋放對象 – cgossain 2010-11-29 00:42:29

回答

4

[imageLow release][imageHigh release]電話是不必要的,會導致崩潰。由imageNamed:返回的對象是預先自動發佈的,因此您不需要自行發佈它們。

+0

解決我的問題,感謝指出它 – cgossain 2010-11-29 00:53:47

2

而且,你必須在調用super在viewWillAppear中方法:

[super viewWillAppear:animated] 

這還不是什麼原因造成死機,但該文檔說,這是必需的。

相關問題