0
私はCSVファイルを読みましたが、今は文字列を解析して、要素を2D NSMutableArrayに書き出しています。NSMutableArrayは問題を書いていますか?
私は2D配列に要素を書き出しています。NSLogは期待される要素を出力します。
しかし、すべてのファイルを解析して2D配列に書き込むと、NSLogはその行の各列の最後の要素を各行に表示します。
- 行のすべての要素が置き換えられた場合 ???なぜ、...高度に深刻ないくつかは、私はそこに潜む問題とは別に、あなたの例で見ているスラッシュで
for (int i = 1; i < iM; i++) {//was a 1 to pass over the header
//get the row and break up into columns
nsmarrDummy = [NSMutableArray arrayWithArray:[[nsmarrRow objectAtIndex: i] componentsSeparatedByString: nsstrColParse]];
//write each item to the proper column in the 2d array at the given row
for (int j = 0; j < iN; j++) {//<<--
[[nsmarrData objectAtIndex:j] replaceObjectAtIndex:i-1 withObject: [nsmarrDummy objectAtIndex:j]];
NSLog(@"i:%d j:%d item:%@", i, j, [[nsmarrData objectAtIndex:j] objectAtIndex:i-1]);
}
}
//all the following are the same value, but doing the NSLog as it was writing was correct.
NSLog(@"FINAL: i:%d j:%d item:%@", 0, 4, [[nsmarrData objectAtIndex:4] objectAtIndex:0]);
NSLog(@"FINAL: i:%d j:%d item:%@", 0, 5, [[nsmarrData objectAtIndex:5] objectAtIndex:0]);
NSLog(@"FINAL: i:%d j:%d item:%@", 0, 6, [[nsmarrData objectAtIndex:6] objectAtIndex:0]);