我有一張加載了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];
}
}
再次無法再感謝你,另一個漫長的夜晚,簡單的事情似乎不會彈出。我建議您在循環中添加註釋,並在符合條件時僅添加註釋,即if([live isEqualToString:@「Active」])myAnnotation.pinColor = MKPinAnnotationColorGreen; [incidentsMap addAnnotation:myAnnotation]; //如果只想顯示綠色的引腳等等!當你擁有一雙清新的眼睛時,這很容易! } –