我有一個類,我實現了一個NSMutableArray對象。現在,當手機進入橫向模式時,NSMutableArray中的所有對象都將從視圖中刪除(但不是從NSMutableArray中刪除),然後當手機返回到縱向模式時,我將包含在NSMutableArray中的所有對象該視圖,但是當我嘗試訪問我收到的第一個對象時:EXC_BAD_ACCESS。包含的對象上的NSMutableArray EXC_BAD_ACCESS
這是我的代碼:
- (void) setObjects:(BOOL)hidden andWindow:(UIWindow *)win andTxt:(UITextView *)txt andTarget:(id) target {
//view
key = [win.subviews objectAtIndex:0];
key.hidden = hidden;
buttons = [[NSMutableArray alloc] initWithCapacity:1]; //my array
txtsms = txt;
[...]
}
- (void) addButton:(button *)but {
[key addSubview:[but returnButton]];
[buttons addObject:but];
[but release];
}
- (void) hiddenAllKey {
for (UIView *subview in [key subviews])
if ((subview.tag <= startSpecialPunctuation+1)&&(subview.tag >= spaceButton+1))
[subview removeFromSuperview];
}
- (void) showAllKey {
for(int i = 0; i < [buttons count]; ++i)
[key addSubview:[[buttons objectAtIndex:i] returnButton]]; //this is the problem :|
}
@Joe - 你是對的,沒有 '可能是' 它。如果您創建或保留按鈕,則不應在此處發佈。 – hooleyhoop 2011-03-20 09:56:54
@PARTH我該怎麼做? – Andrea 2011-03-20 11:18:03