当用户单击“保存”按钮时,我运行以下代码:
- (IBAction) onSaveChangesClick:(id)sender {
NSMutableString *newGroups = [[NSMutableString alloc] init];
for (int i = 0; i < [self.isInGroupArr count]; i++) {
if ([[self.isInGroupArr objectAtIndex:i] boolValue] == YES) {
[newGroups appendString:[[AppDelegate arrayGroups] objectAtIndex:i]];
[newGroups appendString:@","];
}
}
// remove last : ","
if ([newGroups length] > 0)
newGroups = [NSMutableString stringWithString:[newGroups substringToIndex:[newGroups length] - 1]];
self.contact.groups = newGroups;
[newGroups release];
//[[self navigationController] popViewControllerAnimated:YES];
}
self.IsInGroups
是BOOL
数组,arrayGroups
是(NSString *) array
保存组名。我想将newGroups
字符串添加到arrayGroups[i]
唯一的if (IsInGroups[i] == YES)
.
这段代码生成EXC_BAD_ACCESS
. 为什么?
谢谢。