내 응용 프로그램의 모델이 될 NSObject의 서브 클래스를 만들었습니다.UIViewController 인스턴스에서 사용자 정의 클래스 내의 프리미티브 배열에 액세스 할 수 없습니다.
#include "Cube.h"
@implementation CubeAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
Cube *cube = [[Cube alloc] init];
[cube printContent];
[cube release];
[window makeKeyAndVisible];
}
그러나, 응용 프로그램이 충돌이 나는를 만들려고하면 : 같은 대리자에서 통해 인스턴스 경우
@interface Cube : NSObject {
int cubeState[5][2][2];
}
- (void)printContent;
@end
@implementation Cube
- (id)init {
if (self = [super init]) {
for (int i=0; i<=5; i++) {
for (int j=0; j<=2; j++) {
for (int k=0; k<=2; k++) {
cubeState[i][j][k] = i;
}
}
}
}
return self;
}
- (void)printContent {
for (int i=0; i<=5; i++) {
for (int j=0; j<=2; j++) {
for (int k=0; k<=2; k++) {
NSLog(@"[%d] [%d] [%d] = %d", i, j, k, cubeState[i][j][k]);
}
}
}
}
@end
이 잘 작동 : 클래스는 몇 가지 방법과 같은 인스턴스의 원시적 배열이있다 나중에 큐브 * 큐브 속성과와의 UIViewController의 서브 클래스는 다음과 같은 뷰 컨트롤러의 속성을 통해 큐브 인스턴스 개체에 액세스하려고 :
@interface CustomController : UIViewController {
Cube *cube;
}
@property (nonatomic, retain) Cube *cube;
@end
@implementation CustomController
@synthesize cube;
- (void)dealloc {
[cube release];
[super dealloc];
}
@end
과에 대의원 :
- (void)applicationDidFinishLaunching:(UIApplication *)application {
viewController = [[CustomController alloc]
initWithNibName:@"MainView" bundle:nil];
viewController.cube = [[[Cube alloc] init] autorelease];
[viewController.cube printContent]; // Application crashes here
}
아이디어가 있으십니까? 최대 인덱스가이 한계를 넘어 [4, 1, 1,하지만 당신은 분명 액세스하는 물건은 그래서
충돌이 무엇입니까? 오류가 무엇입니까? 디버거에서 printContent를 실행하면 어떻습니까? 당신은 충돌의 정확한 진술을 확인할 수 있습니까? –