正如您在下面看到的,我以基本的方式模拟了我的问题。我有一个定期调用方法的计时器。在这种方法中,我创建了一个 switch-case 条件来模拟我的想法。
一旦在地图上添加大头针,然后再次读取(大头针不断下降)它们。
我想添加我的图钉,然后只更改代表天气值的标题。
- (IBAction)playBtn:(id)sender {
timer = [NSTimer scheduledTimerWithTimeInterval:(4.0) target:self selector:@selector(control) userInfo:nil repeats:YES];
}
-(void)control{
NSMutableArray *annotationArray = [[[NSMutableArray alloc] init] autorelease];
switch (value%2) {
case 0:
{
// Create some annotations
Annotation *annotation = nil;
annotation = [[Annotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(29.7161,-95.3906);
annotation.color = RGB(13, 0, 182);
annotation.title = @"17";
[annotationArray addObject:annotation];
[annotation release];
annotation = [[Annotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(30.168456,-95.504480);
annotation.color = RGB(0, 182, 146);
annotation.title = @"16";
[annotationArray addObject:annotation];
[annotation release];
// Center map
//self.mapView.visibleMapRect = [self makeMapRectWithAnnotations:annotationArray];
// Add to map
//[self.mapView addAnnotations:annotationArray];
}
break;
case 1:
{
// Create some annotations
Annotation *annotation = nil;
annotation = [[Annotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(29.7161,-95.3906);
annotation.color = RGB(13, 0, 182);
annotation.title = @"27";
[annotationArray addObject:annotation];
[annotation release];
annotation = [[Annotation alloc] init];
annotation.coordinate = CLLocationCoordinate2DMake(30.168456,-95.504480);
annotation.color = RGB(0, 182, 146);
annotation.title = @"25";
[annotationArray addObject:annotation];
[annotation release];
}
break;
}
[self.mapView addAnnotations:annotationArray];
[mapView setNeedsDisplay];
value++;