0

ビューからUITableViewのデータソースにNSStringリターンを挿入するたびに、新しいセルを挿入するための呼び出しが行われると、プログラムがクラッシュします。以下はコードです:

- (void)insertTableObject:(NSString *)thing
{
    if (!locations) locations = [[NSMutableArray alloc] init];
    [locations addObject:[NSString stringWithFormat:@"%@", thing]];
    NSLog(@"%@", locations);
    self.tableContents = [[NSMutableDictionary alloc] initWithObjectsAndKeys:locations,@"", nil];
    self.sortedKeys =[[self.tableContents allKeys] sortedArrayUsingSelector:@selector(compare:)];
    [self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:([locations count]-1) inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}

以下は、印刷された配列と、それに伴うエラーです。

2013-03-23 15:06:32.433 XXX[9149:907] (
"D.C",
la
)
2013-03-23 15:06:32.439 XXX[9149:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x320852a3 0x39f1b97f 0x31fd0b75 0xc05bd 0x33ed854d 0x33ec9685 0x33ec5d55 0x33ec4d27 0x33ec1bf9 0x33ff6b27 0xbeceb 0xf6413 0x33f780c5 0x33f78077 0x33f78055 0x33f7790b 0x33f77e01 0x33ea05f1 0x33e8d801 0x33e8d11b 0x35b815a3 0x35b811d3 0x3205a173 0x3205a117 0x32058f99 0x31fcbebd 0x31fcbd49 0x35b802eb 0x33ee1301 0xb701b 0xb6f70)
libc++abi.dylib: terminate called throwing an exception

「la」が引用符なしで印刷されているのは問題ですか?システムがそのエントリを認識していない可能性がありますか?

4

1 に答える 1

0

私は問題を解決することになった。詳細ビューのセルがあったので、detailViewインデックスを描画するときに、それは存在しませんでした。元の投稿の関数に単純な行を追加して、detailView配列に別の値を追加しました。

于 2013-03-23T22:42:01.593 に答える