2010-05-31 53 views
0
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Congratulations" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"View", nil]; 
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(110, 100, 80, 80)]; 
NSString *imagePath = [NSString stringWithFormat:@"%@", [Array objectAtIndex:x]]; 
UIImage *bkgImg = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:imagePath ofType:@"png"]]; 
imageView.image = bkgImg; 
[bkgImg release]; 
[alert addSubview:imageView]; 
[imageView release]; 
[alert show]; 
[alert release];  

這是我用來創建警報視圖的代碼。目前,我已經設置了它,如果用戶按下其中一個按鈕,它將加載一個新的視圖控制器。它工作正常,直到我添加到UIAlertView子視圖。現在,只要它動畫到新屏幕,它就會使程序崩潰。我相當新的iPhone開發和任何幫助,將不勝感激。UIAlertView與子視圖動畫到新視圖崩潰應用程序

+0

你能發佈崩潰日誌嗎?它可能包含幫助查找崩潰來源的信息。 – 2010-05-31 06:58:20

回答

1

你正在做的:

UIImage *bkgImg = [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource:imagePath ofType:@"png"]]; 
... 
[bkgImg release]; 

+imageWithContentsOfFile返回一個自動釋放UIImage的實例,所以你應該發佈它自己。可能發生的事情是NSAutoreleasePool發送一個-release到一個已被釋放的對象,導致應用程序在稍後崩潰。

我建議您仔細看看http://developer.apple.com/mac/library/documentation/cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html(或者如果存在這些文檔,請參閱同等的iPhone文檔)。

相關問題