0
我想找到位於同一行中的兩個CGPoint
之間的點。我使用斜率和x,p1.x
和p2.x
之間的CGPoints
來計算y,並且比我從新的x
和y
製作CGPoint
,並最終將它添加到結果數組中。但是我得到了這個錯誤。[__NSArrayM CGPointValue]:發送到實例的無法識別的選擇器
[__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;
}
請發佈導致問題的代碼,告訴我們確切發生在哪條線上。觸發問題是對「CGPointValue」的錯誤調用。發佈的代碼永遠不會調用「CGPointValue」。 – Tommy
添加一個異常斷點,以便您可以看到哪一行導致錯誤。 – rdelmar
我現在添加了整個代碼 – Mina