gpt4 book ai didi

objective-c - 右侧标注附件按钮在此代码的注释 View 上不可见

转载 作者:行者123 更新时间:2023-11-29 04:22:14 25 4
gpt4 key购买 nike

我在我的应用程序中实现了以下功能

编译时没有错误。然而,我在模拟器中的 map 注释上看不到正确的附件按钮。我看到了注释,只是上面没有按钮。我缺少什么技巧吗?

- (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;

最佳答案

您确定要添加 Vendor 类型的注释吗?

因为第一个代码块仅为 Vendor 类型的注释设置 rightCalloutAccessoryView。对于任何其他类型,它返回nil,从而产生通用标注(无按钮)。

第二个代码块为除 MKUserLocation 之外的任何注释类型设置 rightCalloutAccessoryView

顺便说一句,您已将按钮操作设置为nil,这意味着点击它时不会发生任何事情。

关于objective-c - 右侧标注附件按钮在此代码的注释 View 上不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12830423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com