, , " iOS 6", , ( ), .
@Ar Ma , annotation ( ), .
image categoryIdNumber, , , viewForAnnotation.
, :
viewForAnnotation addAnnotation. iOS 6 .viewForAnnotation . , , .viewForAnnotation , . 1 2.
, , addAnnotation, categoryIdNumber , , , viewForAnnotation categoryIdNumber .
, , viewForAnnotation , addAnnotation , categoryIdNumber, , , , , .
( iOS), categoryIdNumber , addAnnotation.
, MyAnnotation, catMapId.
, addAnnotation - viewForAnnotation, . (, MyAnnotation viewForAnnotation, .)
, ( viewForAnnotation):
MyAnnotation* myAnn = [[MyAnnotation alloc] init];
myAnn.coordinate = ...
myAnn.title = ...
myAnn.catMapId = categoryIdNumber;
[mapView addAnnotation:myAnn];
viewForAnnotation :
- (MKAnnotationView *) mapView:(MKMapView *)mapingView viewForAnnotation:(id <MKAnnotation>) annotation
{
annView = nil;
if(annotation != mapingView.userLocation)
{
static NSString *defaultPinID = @"MyAnnId";
annView = (MKAnnotationView *)[mapingView dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if ( annView == nil )
{
annView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] ;
annView.canShowCallout = YES;
}
else
{
annView.annotation = annotation;
}
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annView.rightCalloutAccessoryView = rightButton;
if ([annotation isKindOfClass:[MyAnnotation class]])
{
MyAnnotation *myAnn = (MyAnnotation *)annotation;
NSLog(@"myAnn.catMapId %@",myAnn.catMapId);
int myAnnCatMapId = [myAnn.catMapId intValue];
NSString *imageName = nil;
switch (myAnnCatMapId)
{
case 9:
{
imageName = @"PIN_comprare.png";
break;
}
case 10:
{
imageName = @"PIN_mangiare.png";
break;
}
case 11:
{
imageName = @"PIN_mangiare.png";
break;
}
case 12:
{
imageName = @"PIN_vivere.png";
break;
}
default:
{
imageName = @"default.png";
break;
}
}
annView.image = [UIImage imageNamed:imageName];
NSLog(@"annview %d", myAnnCatMapId);
}
}
return annView;
}