以下に示すように、基本的な方法で問題をシミュレートしました。メソッドを定期的に呼び出すタイマーがあります。その方法では、私のアイデアをシミュレートするために 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++;