2010-07-06 48 views
0

我在我的應用程序中使用UINavigationController。 在第一個視圖中,我正在顯示一些信息並且有一個用於從相機加載圖片的按鈕。這工作很好迄今。當圖片加載時,我想在第二個視圖中的UIImageView中顯示圖片。因此我使用下面的代碼。UINavigationController EXC_BAD

MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
CorrectedImageController *imageController = [[CorrectedImageController alloc] initWithNibName:@"CorrectedImageView" bundle:nil]; 
self.correctedImageViewController = imageController; 
[imageController release];  
[delegate.navController pushViewController:imageController animated:YES]; 

第二個視圖被加載並顯示圖片。但是我在調​​試器控制檯中收到EXC_BAD_ACCESS消息,我的應用程序阻止了UI。

在圖片加載爲第二種觀點如下:

- (void)viewDidLoad { 
    MyAppDelegate *delegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    [imageView setImage:delegate.correctedImage]; 
    [super viewDidLoad]; 
} 

可有人告訴我,我做錯了什麼? 我的筆尖文件如下:

-File's Owner (Corrected Image Controller) 
-First Responder (UIResponder) 
-View (UIView) 
--ImageView (UIImageView) 

文件的所有者視圖屬性連接視圖。 而imageView屬性連接到ImageView。

有人可以告訴我,我做錯了什麼?

BR, 馬丁

回答

1

我相信這是因爲你正在呼籲imageController釋放(5號線),然後嘗試pushModalView您剛剛發佈的對象(6號線)。如果你的self.correctedImageViewController保留了imageController,你可以推動self.correctedImageViewController或者在推送後釋放imageController。