在此代码中,在第二个for循环中,如果使用除i和j以外的标识符,则会得到一个EXC_BAD_ACCESS。EXC_BAD_ACCESS for for循环
if (UIDeviceOrientationIsPortrait(deviceOrientation)){
numRows = 4;
numCols = 3;
}else {
numRows = 6;
numCols = 1;
}
for (int row = 0; row < numRows; row++){
for (int col = 0; col < numCols; col++) {
keysArray[row][col] = [[[keys objectAtIndex:0] retain] autorelease];
if (col < numRows)
[keys removeObjectAtIndex:0];
}
}
//Here is the crash
for (int i = 0; i < numRows; i++) {
for (int j = 0; j < numCols; j++){
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.frame = CGRectMake(i * kKeyGap, j * kKeyGap, 57, 57);
[b setImage: [UIImage imageNamed:keysArray[j][i]]
forState:UIControlStateNormal];
[self.view addSubview:b];
}
}
为什么会造成这样的错误?我尝试使用Edit All In Scope来避免丢失一个,但它仍然崩溃。
感谢
你能提供一个例子和/或澄清什么或者不会导致崩溃?在这个例子中,你使用的是i/j ... – nessence 2010-08-27 14:42:49