我有一种情况,我从服务器中的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'

最佳答案

contentArrayNSArray对象的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);

10-08 05:50