我有一個滾動視圖,並添加了一個帶有圖像標籤和按鈕的視圖到滾動視圖。我將操作添加到按鈕,當我運行它時,一切看起來都很好,但是當我點擊某個按鈕時,應用程序與EXC_BAD_ACCESS一起崩潰。我正在使用ARC,因此不確定是否導致問題,但不應該。它似乎無法找到我的行動,就像從內存中釋放出來的東西。這裏是我的代碼:UIButton操作EXC_BAD_ACCESS ARC
-(void)lvlSelected:(id)sender{
NSLog(@"Selected level pack");
}
/*
DISPLPAYPACKS
This will take the loaded level packs and display them in the scroll view for selection
*/
-(void)displayPacks{
//Iterate thru the installed level packs and load some tiles they can select
for (int i = 0; i < installedLevelPacks.count; i++){
levelPack *curPack = [installedLevelPacks objectAtIndex:i];
CGFloat x = i * 110;
//Add the view to contain the rest of our elements
UIView *tileView = [[UIView alloc] initWithFrame:CGRectMake(x, 0, 100, 125)];
//view.backgroundColor = [UIColor greenColor];
//Add a label to the bottom to hold the title
UILabel *titleLbl = [[UILabel alloc] initWithFrame:CGRectMake(0, tileView.frame.origin.y+100, 100, 25)];
titleLbl.textAlignment=UITextAlignmentCenter;
titleLbl.font=[UIFont fontWithName:@"American Typewriter" size:12];
titleLbl.adjustsFontSizeToFitWidth=YES;
titleLbl.text=curPack.title;
//Add the preview image to the tile
UIImageView *previewImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:curPack.previewImg]];
previewImg.frame=CGRectMake(0, 0, 100, 100);
//Add the button over the tile
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.frame = CGRectMake(0, 0, 100, 125);
//Set the tag to the level ID so we can get the pack later
[aButton setTag:i];
[aButton setTitle:curPack.title forState:UIControlStateNormal];
[aButton addTarget:self action:@selector(lvlSelected:) forControlEvents:UIControlEventTouchUpInside];
[tileView addSubview:previewImg];
[tileView addSubview:titleLbl];
[tileView addSubview:aButton];
[lvlScroller addSubview:tileView];
}
//Set the total size for the scrollable content
lvlScroller.contentSize = CGSizeMake(installedLevelPacks.count*110, 125);
}
我在這裏確實失去了一些東西,我以前做過這個,但不與ARC所以這就是爲什麼我堅持上是罪魁禍首。
NSZombie輸出狀態: Objective-C消息被髮送到地址爲0x6b8d530的解除分配對象(zombie)。 
告訴我這個類的名字,以及這個類的對象是在哪裏創建的? –
Inder此方法在UIViewController中,類名稱爲LevelPackViewController。這是在用戶按下按鈕(開始按鈕)時從另一個視圖創建的。 – Chevol
如果我將組件添加到視圖而不是UIScrollView,它可以正常工作,但我顯然不能滾動通過關卡包。然而,點擊它們不會返回錯誤,因此它使我認爲UIScrolView正在被釋放,所以是對按鈕和目標idk的引用。 – Chevol