在此代碼中,在第二個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