我有一个案例,我从服务器中的CSV文件中读取值,然后解析那些删除逗号的文件。这个数据是要绘制的,因此我必须将它转换为CGFloat是否有任何可能的方法?以下是我正在使用的代码。
-(void)connection :(NSURLConnection *) connection didReceiveData:(NSData *)data{
[self serverConnect];
response = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *stripped1 = [response stringByReplacingOccurrencesOfString:@"\r" withString:@""];
NSMutableArray *rows = [NSMutableArray arrayWithArray:[stripped1 componentsSeparatedByString:@"\n"]];
NSMutableArray *contentArray = [NSMutableArray array];
NSArray *components;
for (int i=0;i<[rows count]; i++) {
if(i == 0 || [[rows objectAtIndex:i] isEqualToString:@""]){
continue;
}
components = [[rows objectAtIndex:i] componentsSeparatedByString:@","];
id x = [components objectAtIndex:0] ;
id y = [components objectAtIndex:1];
[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x,@"x",y,@"y", nil]];
NSLog(@"Contents of myData: %@",contentArray);
}
self.scatterPlot = [[TUTSimpleScatterPlot alloc] initWithHostingView:_graphHostingView andData:contentArray];
[self.scatterPlot initialisePlot:0];
}
内容数组包含不是CGFloat的对象。错误恰好出现在这里
-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
if ( [plot.identifier isEqual:@"mainplot"] )
{
NSValue *value = [self.graphData objectAtIndex:index];
**CGPoint point = [value CGPointValue];**
- [__ NSCFDictionary CGPointValue]:无法识别的选择器发送到实例0x6b77c50&#39;
答案 0 :(得分:2)
contentArray
是NSArray
个NSDictionary
个对象,字典条目对象是NSString
,而不是NSValue
。
猜测rt和uc是该点的x,y值:
NSDictionary *entry = [self.graphData objectAtIndex:index];
CGFloat rt = [[entry objectForKey:@"RT"] floatValue];
CGFloat uc = [[entry objectForKey:@"UC"] floatValue];
CGPoint point = CGPointMake(rt, uc);