これが私の問題を理解するために必要なバックグラウンドコードです。ビューコントローラクラスには、levelStartという配列を作成するメソッドがあり、その配列は、その配列で初期化されたゲームクラスに送信されます。次に、この配列を使用して「ゲームをプレイ」する一連の関数があります。 。ビューコントローラのコードは次のとおりです。
NSMutableArray* levelStart = [[NSMutableArray alloc] init];
NSMutableArray* levelFinish = [[NSMutableArray alloc] init];
NSString* startString = [[NSString alloc] initWithString:@"9999999999988888888998888888899888888889988888888998888888899888888889911888888991188888899999999999"];
NSString* finishString = [[NSString alloc] initWithString:@"9999999999988888811998888881199888888889988888888998888888899888888889988888888998888888899999999999"];
int currentsquare;
for (int i = 0; i < 100; i++) {
currentsquare = [startString characterAtIndex:i] - '0';
if (currentsquare == 1) {
NSNumber* numb1 = [[NSNumber alloc] initWithInt:1];
[levelStart addObject:numb1];
}
if (currentsquare == 2) {
NSNumber* numb2 = [[NSNumber alloc] initWithInt:2];
[levelStart addObject:numb2];
}
if (currentsquare == 3) {
NSNumber* numb3 = [[NSNumber alloc] initWithInt:3];
[levelStart addObject:numb3];
}
if (currentsquare == 4) {
NSNumber* numb4 = [[NSNumber alloc] initWithInt:4];
[levelStart addObject:numb4];
}
if (currentsquare == 8) {
NSNumber* numb8 = [[NSNumber alloc] initWithInt:8];
[levelStart addObject:numb8];
}
if (currentsquare == 9) {
NSNumber* numb9 = [[NSNumber alloc] initWithInt:9];
[levelStart addObject:numb9];
}
}
for (int i = 0; i < 100; i++) {
currentsquare = [finishString characterAtIndex:i] - '0';
if (currentsquare == 1) {
NSNumber* fnumb1 = [[NSNumber alloc] initWithInt:1];
[levelFinish addObject:fnumb1];
}
if (currentsquare == 2) {
NSNumber* fnumb2 = [[NSNumber alloc] initWithInt:2];
[levelFinish addObject:fnumb2];
}
if (currentsquare == 3) {
NSNumber* fnumb3 = [[NSNumber alloc] initWithInt:3];
[levelFinish addObject:fnumb3];
}
if (currentsquare == 4) {
NSNumber* fnumb4 = [[NSNumber alloc] initWithInt:4];
[levelFinish addObject:fnumb4];
}
if (currentsquare == 8) {
NSNumber* fnumb8 = [[NSNumber alloc] initWithInt:8];
[levelFinish addObject:fnumb8];
}
if (currentsquare == 9) {
NSNumber* fnumb9 = [[NSNumber alloc] initWithInt:9];
[levelFinish addObject:fnumb9];
}
}
[startString release];
[finishString release];
//NOTE: I took out the intialization of control and level, both which work fine.
myGame = [[Game alloc] initLevel:level With:levelStart AndFinish:levelFinish WithRows:10 WithColumns:10 WithControl:control];
私のゲームクラスでは、これは初期化方法です。
-(id)initLevel:(int)aLevel With:(NSMutableArray*)starter AndFinish:(NSMutableArray*)finisher WithRows:(int)rows WithColumns:(int)cols WithControl:(Coord)aControlSquare{
self = [super init];
if (self != nil){
level = aLevel;
squares = [[NSMutableArray alloc] init];
squares = starter;
finish = [[NSMutableArray alloc] init];
finish = finisher;
}
return self;
}
これで、フリーズし続ける方法はGameにあります。これは、UIgestureレコグナイザーによってトリガーされます。これは、フリーズする行です。
if ([[self squareForCoord:test] intValue] == 8) {
...
}
ここで、squareForCordはテスト座標を取得し、その座標でNSNumberを返します。そのため、すべてのテストが範囲内にあり、フリーズするポイントが配列の範囲内にあることを確認しました。私はすべてを正しく初期化していると思いますが、明らかにそうではありません。これはリリースされたものをリリースすることの問題ではないので、初期化の問題であるに違いないと思います。助けてください。