2010-05-31 55 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文档)。

相关问题