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];    

これは、アラートビューを作成するために使用しているコードです。現在、ユーザーがボタンの1つを押すと、新しいビューコントローラーが読み込まれるように設定しています。UIAlertViewにサブビューを追加するまでは正常に機能しました。これで、新しい画面にアニメーション化するたびに、プログラムがクラッシュするだけです。私はiPhoneの開発にかなり慣れていないので、助けていただければ幸いです。

4

1 に答える 1

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 ドキュメントが存在する場合)をよく見ることをお勧めします。

于 2010-05-31T10:13:37.633 に答える