2

我制作了一个 CGpoints 的 NSMUtableArray,并通过将它们子类化为 NSValue 来存储它们,但我无法获取这些值。在这里,我做了什么。

 CGPoint graphPoint;
    NSMutableArray *pointValues = [[NSMutableArray alloc] init];

    for( int x =0;x<5; x++)
    {
    NSDictionary* xValue = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:x] forKey:@"X"];
    graphPoint.x =x;
    graphPoint.y = [CalculatorBrain runProgram: self.graphingPoint usingVariableValues:xValue];

    [pointValues addObject:[NSValue valueWithCGPoint:graphPoint]];

}

我尝试使用它来获取值,但我只是返回 null

for( int x=0; x<5; x++) {
NSValue *val = [pointValues objectAtIndex:x];
CGPoint point = [val CGpointValue];
NSLog(@"Points = %@", point);
}
4

1 回答 1

3

您不能CGPoint使用%@格式说明符打印 a,因为它不是对象。相反,使用NSStringFromCGPoint()

NSLog(@"%@", NSStringFromCGPoint(myPoint));
于 2012-07-22T23:48:44.737 回答