我用, (值的值)从NSArray获取值。现在我想将它存储在2维浮点数组[] []中。当我尝试给数组赋值时,它给出错误:赋值中的不兼容类型。 我试图转换的值,但我得到了错误:指针值用于预期浮点值。我需要将值存储在2维数组中。我怎么做到的? 谢谢。可以存储浮点类型数组中的id值吗?
@implementation fromFileRead1
NSString *fileNameString;
int numberOfEnemies, numberOfValues;
-(id)init
{
if((self = [super init]))
{
NSString *path = @"/Users/sridhar/Desktop/Projects/exampleOnFile2/enemyDetals.txt";
NSString *contentsOfFile = [[NSString alloc] initWithContentsOfFile:path];
NSArray *lines = [contentsOfFile componentsSeparatedByString:@"\n"];
numberOfEnemies = [lines count];
NSLog(@"The number of Lines: %d", numberOfEnemies);
for (id line in lines)
{
NSLog(@"Line %@", line);
NSString *string1 = line;
NSArray *split1 = [string1 componentsSeparatedByString:@","];
numberOfValues = [split1 count];
NSLog(@"The number of values in Row: %d", numberOfValues);
for (id value in split1)
{
NSLog(@"value %@", value);
float value1;
value1 = [split1 objectAtIndex:2]);
NSLog(@"VAlue of Value1 at index 2: %f", value1);
}
}
}
return self;
}
@end
在enemyDetal.txt我
1,3,3
2,3,2.8
10,2,1.6
请显示一些代码。 – 2010-04-01 10:18:03