문제

This is relevant code:

@property (nonatomic, strong) NSMutableArray *coordinateInPixels;

...

NSLog(@"First log %@",self.coordinateInPixels);
NSLog(@"self.zoomScale %f",self.zoomScale);

if ([self.coordinateInPixels count]>0) {
    NSMutableArray *coordInScala = self.coordinateInPixels;

    for (int i=0; i<[coordInScala count]; i++) {
        CGPoint puntoRicalcolato = CGPointMake([[coordInScala objectAtIndex:i] CGPointValue].x*self.zoomScale,
        [[coordInScala objectAtIndex:i] CGPointValue].y*self.zoomScale);

        [coordInScala replaceObjectAtIndex:i withObject:[NSValue valueWithCGPoint:puntoRicalcolato]];
    }

    [self DrawRoute:coordInScala];

}

NSLog(@"Third log %@",self.coordinateInPixels);

DrawRoute is simple:

- (void)DrawRoute:(NSMutableArray *)coords
{
    self.route = [[ALCRoute alloc] init];
    [self.route setCoord:coords];

    CGRect rettangolo = CGRectMake([[coords objectAtIndex:0] CGPointValue].x, [[coords lastObject] CGPointValue].y, [[coords lastObject] CGPointValue].x-[[coords objectAtIndex:0] CGPointValue].x, [[coords objectAtIndex:0] CGPointValue].y-[[coords lastObject] CGPointValue].y);

    NSLog(@"Second log %@",self.coordinateInPixels);

    [self.route setFrame:rettangolo];
    [self addSubview:self.route];

}

PROBLEM DEFINITION:

The problem is that self.coordinateInPixels' elements are different in second and third log from the first. There aren't any other operation before drawroute, but magically elements change without (obiouvsly apparently) any reason... Any ideas?

Here's the output console:

2013-04-11 12:00:05.265 APP[4233:14c03] First log (
    "NSPoint: {2442.0994, 2088.6094}",
    "NSPoint: {2442.0994, 2088.6094}",
    "NSPoint: {1968.8776, 1395.6793}",
    "NSPoint: {1965.4939, 1390.1688}",
    "NSPoint: {1962.0531, 1384.6427}",
    "NSPoint: {2442.0752, 2088.6128}",
    "NSPoint: {2442.0752, 2088.6128}",
    "NSPoint: {2167.9409, 1604.3606}",
    "NSPoint: {2164.2456, 1598.6599}",
    "NSPoint: {2160.8596, 1593.2056}",
    "NSPoint: {2157.3921, 1587.6027}"
)
2013-04-11 12:00:05.266 APP[4233:14c03] self.zoomScale 0.552063
2013-04-11 12:00:05.266 APP[4233:14c03] Second log (
    "NSPoint: {1348.1931, 1153.0443}",
    "NSPoint: {1348.1931, 1153.0443}",
    "NSPoint: {1086.9448, 770.50317}",
    "NSPoint: {1085.0768, 767.461}",
    "NSPoint: {1083.1772, 764.41022}",
    "NSPoint: {1348.1798, 1153.0461}",
    "NSPoint: {1348.1798, 1153.0461}",
    "NSPoint: {1196.8403, 885.70837}",
    "NSPoint: {1194.8003, 882.56128}",
    "NSPoint: {1192.931, 879.55011}",
    "NSPoint: {1191.0167, 876.45697}"
)
2013-04-11 12:00:05.267 APP[4233:14c03] Third log (
    "NSPoint: {1348.1931, 1153.0443}",
    "NSPoint: {1348.1931, 1153.0443}",
    "NSPoint: {1086.9448, 770.50317}",
    "NSPoint: {1085.0768, 767.461}",
    "NSPoint: {1083.1772, 764.41022}",
    "NSPoint: {1348.1798, 1153.0461}",
    "NSPoint: {1348.1798, 1153.0461}",
    "NSPoint: {1196.8403, 885.70837}",
    "NSPoint: {1194.8003, 882.56128}",
    "NSPoint: {1192.931, 879.55011}",
    "NSPoint: {1191.0167, 876.45697}"
)

SOLUTION!

Changing this:

if ([self.coordinateInPixels count]>0) {
        NSMutableArray *coordInScala = self.coordinateInPixels;

        for (int i=0; i<[coordInScala count]; i++) {
            CGPoint puntoRicalcolato = CGPointMake([[coordInScala objectAtIndex:i] CGPointValue].x*self.zoomScale,
            [[coordInScala objectAtIndex:i] CGPointValue].y*self.zoomScale);

            [coordInScala replaceObjectAtIndex:i withObject:[NSValue valueWithCGPoint:puntoRicalcolato]];
        }

        [self DrawRoute:coordInScala];

    }

With this:

if ([self.coordinateInPixels count]>0) {
    NSMutableArray *coordInScala = [[NSMutableArray alloc] init];

    for (int i=0; i<[self.coordinateInPixels count]; i++) {
        CGPoint puntoRicalcolato = CGPointMake([[self.coordinateInPixels objectAtIndex:i] CGPointValue].x*self.zoomScale,
                                                   [[self.coordinateInPixels objectAtIndex:i] CGPointValue].y*self.zoomScale);

        [coordInScala addObject:[NSValue valueWithCGPoint:puntoRicalcolato]];
    }

    [self DrawRoute:coordInScala];

}

and all start working correctly...

도움이 되었습니까?

해결책

In this line:

    NSMutableArray *coordInScala = self.coordinateInPixels;

You are not making a new array. coordInScala is a reference to self.coordinateInPixels so any change you make, you are actually making them to self.coordinateInPixels.

You probably want this:

    NSMutableArray *coordInScala = self.coordinateInPixels.mutableCopy;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top