この次の関数をアプリに実装しています
コンパイル時にエラーは発生しません。それでも、シミュレーターのマップ注釈に適切なアクセサリボタンが表示されません。ボタンがないというだけの注釈が表示されます。私が行方不明になっているこれへのトリックはありますか?
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id
<MKAnnotation>)annotation
{
static NSString *identifier = @"Vendor";
//Set upt the right accessory button
UIButton *myDetailAccessoryButton = [UIButton
buttonWithType:UIButtonTypeDetailDisclosure];
myDetailAccessoryButton.frame = CGRectMake(0, 0, 23, 23);
myDetailAccessoryButton.contentVerticalAlignment =
UIControlContentVerticalAlignmentCenter;
myDetailAccessoryButton.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentCenter;
[myDetailAccessoryButton addTarget:self
action:nil
forControlEvents:UIControlEventTouchUpInside];
if ([annotation isKindOfClass:[Vendor class]])
{
MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [self.mapView
dequeueReusableAnnotationViewWithIdentifier:identifier];
if (annotationView == nil)
{
annotationView = [[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:identifier];
annotationView.rightCalloutAccessoryView = myDetailAccessoryButton;
annotationView.enabled = YES;
annotationView.canShowCallout = YES;
annotationView.calloutOffset = CGPointMake(-5, 5);
}
else
{
annotationView.annotation = annotation;
}
return annotationView;
}
return nil;
}
編集このコードは機能しましたが、上記のコードは機能しません。
何故ですか?
if ([annotation isMemberOfClass:[MKUserLocation class]])
return nil;
MKPinAnnotationView *annView=[[MKPinAnnotationView alloc]
initWithAnnotation:annotation
reuseIdentifier:@"currentloc"];
UIButton *myDetailButton = [UIButton
buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment =
UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment =
UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self
action:nil
forControlEvents:UIControlEventTouchUpInside];
annView.rightCalloutAccessoryView = myDetailButton;
annView.animatesDrop=NO;
annView.canShowCallout = YES;
annView.calloutOffset = CGPointMake(-5, 5);
return annView;