gpt4 book ai didi

ios - 将 NSobject 转换为 CGFPoint

转载 作者:行者123 更新时间:2023-11-29 11:16:53 25 4
gpt4 key购买 nike

我有一个案例,我从服务器的 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'

最佳答案

contentArrayNSDictionary 对象的 NSArray,字典条目对象是 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);

关于ios - 将 NSobject 转换为 CGFPoint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9085154/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com