我有一张地图,上面有 3 种标准颜色的别针。这些引脚根据解析并存储到数组中的 xml 中的值进行着色。
我想添加一个带有 2 个按钮的分段控件:
按钮 1 仅显示绿色引脚。
和按钮 2 仅显示红色和紫色引脚。
我已阅读有关为每种引脚颜色添加 3 个不同的阵列并删除引脚阵列的信息,但我想保留一个阵列。如果可能的话,我将如何做到这一点。我知道如何实现分段控件,但我不知道如何打开或关闭它们。
这是我的 for 循环:创建引脚并分配 3 种颜色,效果很好。
//Count the array of annotations and add them dynamically to the map.
for (int i = 0; i < locationArray.count; i++) {
myAnnotation =[[MyAnnotation alloc] init];
NSString *latString = [[locationArray objectAtIndex:i]xmlLat];
NSString *lonString = [[locationArray objectAtIndex:i]xmlLon];
type = [[locationArray objectAtIndex:i]xmlType];
imageId = [[locationArray objectAtIndex:i]xmlImageId];
address = [[locationArray objectAtIndex:i]xmlAddress];
email = [[locationArray objectAtIndex:i]xmlEmail];
phone = [[locationArray objectAtIndex:i]xmlPhone];
live = [[locationArray objectAtIndex:i]xmlLive];
form = [[locationArray objectAtIndex:i]xmlForm];
name = [[locationArray objectAtIndex:i]xmlName];
//Change the 0 to Active ticket and 1 to Closed 2 to False and 3 to Not Found and 4 to Other
if ([live isEqualToString:@"0"]) {
live = @"Active";
}
else if ([live isEqualToString:@"1"]){
live = @"Closed";
}
else if([live isEqualToString:@"2"]){
live = @"False";
}
else if ([live isEqualToString:@"3"]){
live = @"Not Found";
}
else if ([live isEqualToString:@"4"]){
live = @"Other";
}
double theLatitude = [latString doubleValue];
double theLongtitude = [lonString doubleValue];
userLocation.latitude=theLatitude;
userLocation.longitude=theLongtitude;
myAnnotation.coordinate=userLocation;
myAnnotation.title=[NSString stringWithFormat:@"%@", imageId];
myAnnotation.subtitle=[NSString stringWithFormat:@"%@", type];
//Setting pin colours here based on value from XML
if ([live isEqualToString:@"Active"]){
myAnnotation.pinColor = MKPinAnnotationColorGreen;
}else if ([live isEqualToString:@"Closed"]){
myAnnotation.pinColor = MKPinAnnotationColorRed;
}
else if ([live isEqualToString:@"Not Found"]){
myAnnotation.pinColor = MKPinAnnotationColorPurple;
}
[incidentsMap addAnnotation:myAnnotation];
}
这是我的分段控制
-(IBAction)segmentedControl:(id)sender{
if (mapFilter.selectedSegmentIndex == 0) {
NSLog(@"Active");
}
else if (mapFilter.selectedSegmentIndex == 1){
NSLog(@"Closed");
//Remove Red and Purple Pins here from view when segmented control button button is touched.........................
}
else if (mapFilter.selectedSegmentIndex == 2){
UIAlertView *mapSelector = [[UIAlertView alloc]initWithTitle:@"Select Map Type" message:@"Choose from 3 map views" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Default", @"Hybrid", @"Satelite", nil];
[mapSelector show];
}
}