objective-c 結果が違う
Posted: 2011年4月27日(水) 00:41
CSVファイルを読み込むという処理を作っております。
ただ問題が御座いまして変数に文字列を入れた物を
パスとして指定するとファイルが読み込めません。
NSString* fileName = [[NSString alloc] initWithString:@"2010_fall"];
と記載すれば読み込めるのですが
NSString* fileName = [[NSString alloc] initWithString:[[index objectAtIndex:(indexPath.row)] objectAtIndex:3]];
だと読み込めません。
[[index objectAtIndex:(indexPath.row)] objectAtIndex:3]には2010_fallが入っております。
NSLog( @"%@", fileName );と出力してみても値は同じ物が入っております。(2010_fall)
原因が全くわからないのですが
これだけでは問題ないようでしたら詳細のソースを貼ります。
ただ問題が御座いまして変数に文字列を入れた物を
パスとして指定するとファイルが読み込めません。
NSString* fileName = [[NSString alloc] initWithString:@"2010_fall"];
と記載すれば読み込めるのですが
NSString* fileName = [[NSString alloc] initWithString:[[index objectAtIndex:(indexPath.row)] objectAtIndex:3]];
だと読み込めません。
[[index objectAtIndex:(indexPath.row)] objectAtIndex:3]には2010_fallが入っております。
NSLog( @"%@", fileName );と出力してみても値は同じ物が入っております。(2010_fall)
原因が全くわからないのですが
これだけでは問題ないようでしたら詳細のソースを貼ります。
NSString* fileName = [[NSString alloc] initWithString:[[index objectAtIndex:(indexPath.row)] objectAtIndex:3]];
//NSString* fileName = [[NSString alloc] initWithString:@"2010_fall"];
NSLog( @"%@", fileName );
NSString* path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"csv"];
NSError* error = nil;
int enc = NSUTF8StringEncoding;
NSString* text = [NSString stringWithContentsOfFile:path encoding:enc error:&error];
NSArray* lines = [text componentsSeparatedByString:@"\n"]; // ファイルの分割