0
我有這個代碼創建圖像:EXC_BAD_ACCESS致命錯誤
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
background = [[UIImageView alloc]initWithFrame:CGRectMake(150, 60, 180, 180)];
result = [[UIImageView alloc]initWithFrame:CGRectMake(150, 60, 180, 180)];
[background setImage:[UIImage imageNamed:[defaults objectForKey:@"colour"]]];
[self.view addSubview:background];
[self.view insertSubview:result aboveSubview:background];
這是我viewWillAppear
。當我按下一個按鈕,出現這種情況:
- (IBAction)oneToSix {
int rNumber = (arc4random() % 6) + 1;
[result setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@", rNumber]]];
}
但它可以讓這種致命的錯誤:Thread one: Program received signal: "EXC_BAD_ACCESS".
在setImage
一部分,當我按下按鈕。問題是什麼?我的新目標C.
感謝您的回答。我有ARC(自動引用計數)的Xcode 4.2。我還需要釋放它們嗎? – gadgetmo
如果使用ARC,則不需要釋放 – Lunayo
當使用ARC時,它會在'viewWillDisappear'上發佈嗎? – gadgetmo