私のプログラムの基本的な構造では、ユーザーが格納されたテキストファイルに対応するUITableViewから項目を選択します。ファイルは配列と辞書に読み込まれます。配列にはキーがあります(私は辞書自体からキーを取得できますが、これは私の質問ではありません)。ファイルから読み取るときにクラッシュログなしでiPadアプリがクラッシュする
ビューは、マスタビューにキーがあるUISplitViewに変更され、ディテールビューには、そのキーに関連付けられているディクショナリ内の項目があります。この場合、ユーザーが回答を選択する一連の「はい/いいえ」の質問です。
私の問題はこれです:UITableView(最初の画面)のセルをクリックすると、正常に動作し、データは完全に読み込まれます。私がUITableViewに戻り、同じセルをもう一度クリックすると、プログラムがクラッシュします。ここで、リードイン-からのファイルの方法は次のとおりです。
-(NSArray *)readFromFile:(NSString *)filePath{
// NSLog(@"Path was: %@", filePath);
NSString *file = [[NSString alloc] initWithContentsOfFile:filePath];
// NSLog(@"File was: %@", file);
NSScanner *fileScanner = [[NSScanner alloc] initWithString:file];
NSString *held;
NSString *key;
NSMutableArray *detailStrings;
NSMutableArray *keys = [[NSMutableArray alloc] init];
NSMutableDictionary *details = [[NSMutableDictionary alloc] init];
/**
This is where the fun stuff happens!
**/
while(![fileScanner isAtEnd]){
//Scan the string into held
[fileScanner scanUpToString:@"\r" intoString:&held];
NSLog(@"Inside the while loop");
// If it is a character, it's one of the Key points, so we do the management necessary
if ([[NSCharacterSet lowercaseLetterCharacterSet] characterIsMember:[[held lowercaseString] characterAtIndex: 0]]){
NSArray *checkers = [[NSArray alloc] initWithArray:[held componentsSeparatedByString:@"\t"]];
NSLog(@"Word at index 2: %@", [checkers objectAtIndex:2]);
if(detailStrings != nil){
[details setObject:detailStrings forKey:key];
[detailStrings release];
}
NSLog(@"After if statement");
key = [checkers objectAtIndex:2];
[keys addObject:(NSString *) key];
detailStrings = [[NSMutableArray alloc] init];
}
else if ([[NSCharacterSet decimalDigitCharacterSet] characterIsMember:[[held lowercaseString] characterAtIndex: 0]]){
NSArray *checkers = [[NSArray alloc] initWithArray:[held componentsSeparatedByString:@"\t"]];
NSLog(@"Word at index 1: %@", [checkers objectAtIndex:1]);
[detailStrings addObject:[checkers objectAtIndex:1]];
}
}
NSLog(@"File has been read in");
[details setObject:detailStrings forKey:key];
NSArray *contents = [[NSArray alloc] initWithObjects:(NSMutableArray *) keys, (NSMutableDictionary *) details, nil];
[detailStrings release];
return contents;
}
私は
if(detailStrings != nil)
文の中のプログラムがクラッシュすることを決定しました。これは、私がやっているはずのメモリ管理が行方不明だからだと思うが、どこが間違っているのか分からないからだ。問題についてのアイデア、または私にログを与えずにクラッシュする理由は何ですか?
を読むなぜあなたはチェックしますか?明らかに、if文の前に値を割り当てたことはありません。それとも私は何かが恋しい? –
コールスタックとは何か、またはクラッシュする理由を教えてください。 –
さらに考えてみたら、解放されたポインタ 'detailStrings'があると思います。それを再定義しても、それは「無」にはなりません。 –