[__NSArrayM CGPointValue]:发送到实例的无法识别的选择器

时间:2014-05-05 15:06:10

标签: objective-c nsmutablearray cgpoint

我想找到位于同一行的两个CGPoint之间的点。我在CGPointsp1.x之间使用斜率和x,p2.x计算y,而不是从新CGPointx计算y最后将其添加到结果数组中。但我得到了这个错误。

  

[__ NSArrayM CGPointValue]:发送到实例的无法识别的选择器   0xa08e910'NSInvalidArgumentException',原因:' - [__ NSArrayM   CGPointValue]:无法识别的选择器发送到实例0xa08e910'

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

CGPoint p5=CGPointMake(158, 339.5);
CGPoint p6=CGPointMake(156.5, 339.5);
CGPoint p7=CGPointMake(65.5, 312);
CGPoint p8=CGPointMake(44.5, 101);

[pointsinbetween addObject:[NSValue valueWithCGPoint:p5]];
[pointsinbetween addObject:[NSValue valueWithCGPoint:p6]];
[pointsinbetween addObject:[NSValue valueWithCGPoint:p7]];
[pointsinbetween addObject:[NSValue valueWithCGPoint:p8]];
NSLog(@"points in between %@",[self extendedarray:pointsinbetween]);

   }


-(float)slopeCalculator:(CGPoint)firstpoint params:(CGPoint)secondpoint
{
    float tempx=firstpoint.x-secondpoint.x;
    float tempy=firstpoint.y-secondpoint.y;
    if ((tempy>0) && (tempx>0)) {
        return tempy/tempx;
    }
    else{
        return 0;
    }

}

-(NSMutableArray*)findpointnewversion:(CGPoint)firstpoint param:(CGPoint)secpoint nextparam:(float)slope
    {
        NSMutableArray *pointset=[[NSMutableArray alloc]init];
        float y;
        float j=firstpoint.x+0.5;
        int inty;
        while (j< secpoint.x) {

            y=slope*j-slope*firstpoint.x-firstpoint.y;
            float fractional=y-truncf(y);
            if ((y>0) && (slope!=0)) {
                if (fractional>0.5) {
                    inty=(int)y;
                    inty++;
                    CGPoint ptemp=CGPointMake(j,inty);
                    [pointset addObject:[NSValue valueWithCGPoint:ptemp]];
                }
                else{
                    inty=(int)y;
                    CGPoint ptemp=CGPointMake(j,inty);
                    [pointset addObject:[NSValue valueWithCGPoint:ptemp]];

                }

            }
            j=j+0.5;
        }
        return pointset;

}
-(NSMutableArray*)extendedarray:(NSMutableArray*)param
{
    NSMutableArray *extendset=[[NSMutableArray alloc]init];
    int j=0;
    while (j<=param.count) {
        CGPoint p1=CGPointFromString([param objectAtIndex:j]);
        j++;
        CGPoint p2=CGPointFromString([param objectAtIndex:j]);
        j++;
        float slope=[self slopeCalculator:p1 params:p2];
        if (p1.x<p2.x) {
            [extendset addObjectsFromArray:[self findpointnewversion:p1 param:p2 nextparam:slope]];
        } else {
            [extendset addObjectsFromArray:[self findpointnewversion:p2 param:p1 nextparam:slope]];
        }
    }    return extendset;
}

1 个答案:

答案 0 :(得分:2)

CGPointFromString()无法正常工作,因为您的数组不包含字符串但NSValue对象

而不是CGPoint p1=CGPointFromString([param objectAtIndex:j]);[params[j] CGPointValue];