0

これは関連するコードです:

@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 は単純です:

- (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];

}

問題の定義:

問題は、self.coordinateInPixels の要素が 1 つ目と 2 つ目と 3 つ目のログで異なることです。drawroute の前に他の操作はありませんが、魔法のように要素は (どうやら) 理由もなく変更されます... 何かアイデアはありますか?

出力コンソールは次のとおりです。

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}"
)

解決!

これを変更する:

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];

    }

これとともに:

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];

}

すべてが正しく機能し始めます...

4

1 に答える 1

1

この行で:

    NSMutableArray *coordInScala = self.coordinateInPixels;

新しい配列を作成していません。coordInScalaは への参照であるself.coordinateInPixelsため、実際に行う変更はself.coordinateInPixels.

おそらくこれが必要です:

    NSMutableArray *coordInScala = self.coordinateInPixels.mutableCopy;
于 2013-04-11T10:29:43.177 に答える