【问题标题】:Why am I unable to remove my annotations from mapview?为什么我无法从 mapview 中删除我的注释?
【发布时间】:2012-06-07 02:52:00
【问题描述】:

为什么我无法从地图视图中删除我的注释?

我的代码:

  • (void)viewDidAppear:(BOOL)动画{ [超级 viewDidAppear:动画]; [自己成为FirstResponder];

    NSMutableArray *annotations = [[NSMutableArray alloc]init];

    NSString *path = [[NSBundle mainBundle] pathForResource:@"data" ofType:@"plist"]; NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];

    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"blackKey"]) { NSLog(@"Black is on");

    NSArray *ann = [dict objectForKey:@"Category1"];

    for(int i = 0; i

    NSString *coordinates = [[ann objectAtIndex:i] objectForKey:@"Coordinates"];
    
    double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue];
    double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue];
    
    MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];
    CLLocationCoordinate2D theCoordinate;
    theCoordinate.latitude = realLatitude;
    theCoordinate.longitude = realLongitude;
    
    myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);
    
    myAnnotation.title = [[ann objectAtIndex:i] objectForKey:@"Name"];
    myAnnotation.subtitle = [[ann objectAtIndex:i] objectForKey:@"Address"];
    myAnnotation.icon = [[ann objectAtIndex:0] objectForKey:@"Icon"];
    
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"blackKey"])
    {
        NSLog(@"Black is on");
        [mapView addAnnotation:myAnnotation];
        [annotations addObject:myAnnotation];
    
    }   else 
        {
            NSLog(@"Black is off");
    
            [self.mapView removeAnnotation:myAnnotation];
    
    
        } 
    
    }
    

    }

    否则 { //没做什么 }

     }
    

[self.mapView removeAnnotation:myAnnotation]; 不适合我

【问题讨论】:

    标签: ios xcode annotations


    【解决方案1】:

    没有什么可以删除的。您创建注释,然后根据对 blackKey 的检查,您可以添加或删除它。但是,当您删除它时,您之前从未添加过它。

    【讨论】:

    • 好的,谢谢! A 已经使用 removeAnnotationS 删除了注释
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-22
    • 2017-08-17
    相关资源
    最近更新 更多