【发布时间】:2011-03-20 09:20:24
【问题描述】:
我有一个实现 NSMutableArray 对象的类。现在,当手机进入横向模式时,NSMutableArray 中的所有对象都从视图中删除(但不是从 NSMutableArray 中),然后当手机返回纵向模式时,我将 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 - 你是对的,没有“可能”。如果您尝试创建或保留按钮,则不应在此处释放它。
标签: iphone objective-c memory-management exc-bad-access