Arrays 在其他实例中访问数组值
在我的应用程序中,我试图访问数组值,但数组返回零值。我已经在这个问题上纠缠了几个小时,似乎无法解决它。因此,任何帮助都将不胜感激:Arrays 在其他实例中访问数组值,arrays,xcode,Arrays,Xcode,在我的应用程序中,我试图访问数组值,但数组返回零值。我已经在这个问题上纠缠了几个小时,似乎无法解决它。因此,任何帮助都将不胜感激: @implementation MyScene{ NSMutableArray *_touchPoints; } -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint touchPoint = [[touches anyObject] locationInNod
@implementation MyScene{
NSMutableArray *_touchPoints;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchPoint = [[touches anyObject] locationInNode:self.scene];
[self clearTouchPoints];
[self addTouchPointToMove:touchPoint];
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint touchPoint = [[touches anyObject] locationInNode:self.scene];
CGPoint targetPoint = CGPointMake(touchPoint.x , touchPoint.y - delta.y);
[self addTouchPointToMove:touchPoint];
NSLog(@"Value: %lf", touchPoint.y);
}
- (void)move:(NSNumber *)_tempTime{
CGPoint currentPoint = [_touchPoints[0] CGPointValue];
CGPoint targetPoint = [_touchPoints[1] CGPointValue];
NSLog(@"Check Value: %lf", targetPoint.y);
}
- (void)addTouchPointToMove:(CGPoint)point {
[_touchPoints addObject:[NSValue valueWithCGPoint:point]];
}
- (void)clearTouchPoints {
[_touchPoints removeAllObjects];
}
数组从未初始化(例如,
\u接触点=[NSMutableArray new];
),因此它是nil
。尝试调用nil
对象上的方法不会产生任何效果,也不会抱怨(即不会引发异常)。因此,在addTouchPointToMove
方法中:
[_touchPoints addObject:[NSValue valueWithCGPoint:point]];
什么也不做
在init
方法中,初始化数组